Sha256: a8ef95bcbf757670b5f59fc6bb31761314990cfce1128e435ea5ce522d88cf8a

Contents?: true

Size: 998 Bytes

Versions: 9

Compression:

Stored size: 998 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?(TimeoutError) || exception.is_a?(SocketError)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
geocoder-1.3.1 examples/reverse_geocode_job.rb
geocoder-1.3.0 examples/reverse_geocode_job.rb
geocoder-1.2.14 examples/reverse_geocode_job.rb
geocoder-1.2.13 examples/reverse_geocode_job.rb
geocoder-1.2.12 examples/reverse_geocode_job.rb
geocoder-1.2.11 examples/reverse_geocode_job.rb
geocoder-1.2.10 examples/reverse_geocode_job.rb
geocoder-1.2.9 examples/reverse_geocode_job.rb
geocoder-1.2.8 examples/reverse_geocode_job.rb