New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Async geocoding with sidekiq #593
Comments
I'm not sure this warrants an addition to Geocoder but perhaps something could be added to /examples? |
Just worked through this - here's an example of how it can be done without adding code to Geocoder. I used Sidekiq - so you'll have to set it up first, but implementation is pretty quick. In this example, I'm using zipcode to look up latitude and longitude. You'll want to remove the geocoded_by and after_validation lines from your model if they're in there. in the controller:
then create a worker:
Feel free to add this to /examples. |
@wasafiri thanks! I just added a simplified version of this as an example. I'm closing this issue for now, but if anyone wants to submit a pull request for a generalized worker that could be used for any geocoded ActiveRecord class (ie, accepts a class name as well as an ID) I'd certainly consider merging. |
I also wanted to convert my sync ActiveRecord geocoding: geocoded_by :geocoded_by
after_validation :geocode, if: :geocoded_by_changed? To conditionally happen async. (e.g. When user is updating one record, do it sync, but when updating a batch of records, do it async) I understand that I could remove the ActiveRecord geocoding altogether and geocode manually in controllers, but that seems less convenient and I might forget a spot where I update model attributes and forget to geocode. Ideas welcomed, otherwise I suppose I'll just have to remove all the convenient ActiveRecord bits. |
One other thought is that even if I wanted it to always happen async, it'd be nice to be able to do that with like an |
It would be convenient to be able to run the geocoding in a worker process like sidekiq or resque
There's a (slightly outdated) fork with sidekiq implemented:
https://github.com/rdeshpande/geocoder/blob/master/lib/geocoder/stores/active_record.rb#L241
Would this be possible at all?
The text was updated successfully, but these errors were encountered: