-1

The issue is I keep hitting the OVER_QUERY_LIMIT error when trying to geocode gem locations on a Google Map . I understand that there is a limit to the rate at which you can call the geocoder (as well as the daily limit on total volume), so I need to introduce a pause in between each result in the array.

How do I pause/delay in Rails Controller method to slow it down?

geo_localization = "#{latitude},#{longitude}" query = Geocoder.search(geo_localization).first place = query.address

Santosh Kumbhar
  • 183
  • 3
  • 15

2 Answers2

0

In the method definition add sleep and that should do the trick for you

def geolocation
  begin
    ...
  rescue Geocoder::OverQueryLimitError
    sleep 2
    retry
  end
end

Also, there is an alternative, to this, you have an option timeout that comes with geocode. You need to create a file config/initializers/geocoder.rb and set the following. This option, I have not tested though.

Geocoder.configure(
  timeout: 10
)

Take a look at this as well, it could be any of those cases for you and the only thing you can do now is wait.

0

Use sleep inside method like so:

sleep 2

That'll sleep for 2 seconds.

Be careful to give an argument. If you just run sleep, the process will sleep forever. (This is useful when you want a thread to sleep until it's woken.)

Akash Kinwad
  • 704
  • 2
  • 7
  • 22