Sha256: 6af717212ffd9630442076a795a8fc601e5e16a119a95790967aa1df1ee8d0d6

Contents?: true

Size: 1000 Bytes

Versions: 43

Compression:

Stored size: 1000 Bytes

Contents

# This class implements an ActiveJob job for performing reverse-geocoding
# asynchronously. Example usage:

# if @location.save && @location.address.blank?
#   ReverseGeocodeJob.perform_later(@location)
# end

# Be sure to configure the queue adapter in config/application.rb:
# config.active_job.queue_adapter = :sidekiq

# You can read the Rails docs for more information on configuring ActiveJob:
# http://edgeguides.rubyonrails.org/active_job_basics.html

class ReverseGeocodeJob < ActiveJob::Base
  queue_as :high

  def perform(location)
    address = address(location)

    if address.present?
      location.update(address: address)
    end
  end

  private

  def address(location)
    Geocoder.address(location.coordinates)
  rescue => exception
    MonitoringService.notify(exception, location: { id: location.id })

    if retryable?(exception)
      raise exception
    end
  end

  def retryable?(exception)
    exception.is_a?(Timeout::Error) || exception.is_a?(SocketError)
  end
end

Version data entries

43 entries across 43 versions & 4 rubygems

Version Path
really-broken-geocoder-1.5.1 examples/reverse_geocode_job.rb
geocoder-1.5.1 examples/reverse_geocode_job.rb
geocoder-1.5.0 examples/reverse_geocode_job.rb
geocoder-1.4.9 examples/reverse_geocode_job.rb
geocoder-1.4.8 examples/reverse_geocode_job.rb
geocoder-1.4.7 examples/reverse_geocode_job.rb
geocoder-1.4.6 examples/reverse_geocode_job.rb
geocoder-1.4.5 examples/reverse_geocode_job.rb
geocoder-1.4.4 examples/reverse_geocode_job.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/geocoder-1.4.3/examples/reverse_geocode_job.rb
geocoder-1.4.3 examples/reverse_geocode_job.rb
geocoder-1.4.2 examples/reverse_geocode_job.rb
geocoder-1.4.1 examples/reverse_geocode_job.rb
geocoder-1.4.0 examples/reverse_geocode_job.rb
geocoder-1.3.7 examples/reverse_geocode_job.rb
geocoder-1.3.6 examples/reverse_geocode_job.rb
geocoder-1.3.5 examples/reverse_geocode_job.rb
broken-geocoder-1.3.6 examples/reverse_geocode_job.rb
broken-geocoder-1.3.5 examples/reverse_geocode_job.rb
broken-geocoder-1.3.4 examples/reverse_geocode_job.rb