2024-04-26 12:59:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
class ReverseGeocodingJob < ApplicationJob
|
2024-04-26 12:59:58 -04:00
|
|
|
queue_as :reverse_geocoding
|
2024-03-15 18:27:31 -04:00
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
def perform(klass, id)
|
2025-01-07 07:41:09 -05:00
|
|
|
return unless DawarichSettings.reverse_geocoding_enabled?
|
2024-03-24 13:09:00 -04:00
|
|
|
|
2024-11-24 09:28:09 -05:00
|
|
|
rate_limit_for_photon_api
|
2024-11-24 08:56:20 -05:00
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
data_fetcher(klass, id).call
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def data_fetcher(klass, id)
|
|
|
|
|
"ReverseGeocoding::#{klass.pluralize.camelize}::FetchData".constantize.new(id)
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|
2024-11-24 09:28:09 -05:00
|
|
|
|
|
|
|
|
def rate_limit_for_photon_api
|
2025-01-07 07:12:14 -05:00
|
|
|
return unless DawarichSettings.photon_enabled?
|
2024-11-24 09:28:09 -05:00
|
|
|
|
2025-01-07 07:12:14 -05:00
|
|
|
sleep 1 if DawarichSettings.photon_uses_komoot_io?
|
2024-11-24 09:28:09 -05:00
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|