diff --git a/README.md b/README.md index 26915ed7b4dd643ca71d540f0c0bdd6e1849c2bf..dfa1370d4ef7bf2f4be4704be0b94e618ad8f3d5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/tasks/geocoder.rake b/lib/tasks/geocoder.rake index 33ed4829e1ed76c624106d0fae5deefef82378f7..9bb15c5b6522b93230d98f6cc28e7124f51e09ad 100644 --- a/lib/tasks/geocoder.rake +++ b/lib/tasks/geocoder.rake @@ -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