Skip to content
Snippets Groups Projects
Commit e7abcbe1 authored by Moncef Belyamani's avatar Moncef Belyamani
Browse files

Add sleep option for geocode rake task.

parent 3b0921c9
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,9 @@ If you have just added geocoding to an existing application with a lot of object ...@@ -98,7 +98,9 @@ If you have just added geocoding to an existing application with a lot of object
rake geocode:all CLASS=YourModel rake geocode:all CLASS=YourModel
Geocoder will print warnings if you exceed the rate limit for your geocoding service. Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `sleep` option to the rake task, like so:
rake geocode:all CLASS=YourModel sleep=0.25
Request Geocoding by IP Address Request Geocoding by IP Address
......
...@@ -2,11 +2,13 @@ namespace :geocode do ...@@ -2,11 +2,13 @@ namespace :geocode do
desc "Geocode all objects without coordinates." desc "Geocode all objects without coordinates."
task :all => :environment do task :all => :environment do
class_name = ENV['CLASS'] || ENV['class'] class_name = ENV['CLASS'] || ENV['class']
sleep_timer = ENV['SLEEP'] || ENV['sleep']
raise "Please specify a CLASS (model)" unless class_name raise "Please specify a CLASS (model)" unless class_name
klass = class_from_string(class_name) klass = class_from_string(class_name)
klass.not_geocoded.each do |obj| klass.not_geocoded.each do |obj|
obj.geocode; obj.save obj.geocode; obj.save
sleep(sleep_timer.to_f) if sleep_timer.present?
end end
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment