Skip to content
Snippets Groups Projects
Commit bb2d338a authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge pull request #480 from monfresh/geocode-with-sleep

Add sleep option for geocode rake task.
parents 3b0921c9 946dffb7
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
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
......
......@@ -2,11 +2,13 @@ namespace :geocode do
desc "Geocode all objects without coordinates."
task :all => :environment do
class_name = ENV['CLASS'] || ENV['class']
sleep_timer = ENV['SLEEP'] || ENV['sleep']
raise "Please specify a CLASS (model)" unless class_name
klass = class_from_string(class_name)
klass.not_geocoded.each do |obj|
obj.geocode; obj.save
sleep(sleep_timer.to_f) unless sleep_timer.nil?
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