Sha256: d75a524a6702d2dcfed9a85dd96f3b58caf6e421532ba96ff74a9f58685bfbc1

Contents?: true

Size: 544 Bytes

Versions: 1

Compression:

Stored size: 544 Bytes

Contents

module AuthTrail
  class GeocodeJob < Rails::VERSION::MAJOR >= 5 ? ApplicationJob : ActiveJob::Base
    def perform(login_activity)
      result =
        begin
          Geocoder.search(login_activity.ip).first
        rescue => e
          Rails.logger.info "Geocode failed: #{e.message}"
          nil
        end

      if result
        login_activity.update!(
          city: result.try(:city).presence,
          region: result.try(:state).presence,
          country: result.try(:country).presence
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authtrail-0.1.3 app/jobs/auth_trail/geocode_job.rb