diff --git a/Gemfile b/Gemfile index a1a27f8c..c096f50e 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ gem 'rswag-ui' gem 'shrine', '~> 3.6' gem 'sidekiq' gem 'sidekiq-cron' +gem 'sidekiq-limit_fetch' gem 'sprockets-rails' gem 'stimulus-rails' gem 'tailwindcss-rails' diff --git a/Gemfile.lock b/Gemfile.lock index e9d78b74..5e910553 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -370,6 +370,8 @@ GEM fugit (~> 1.8, >= 1.11.1) globalid (>= 1.0.1) sidekiq (>= 6.5.0) + sidekiq-limit_fetch (4.4.1) + sidekiq (>= 6) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -465,6 +467,7 @@ DEPENDENCIES shrine (~> 3.6) sidekiq sidekiq-cron + sidekiq-limit_fetch simplecov sprockets-rails stimulus-rails diff --git a/app/jobs/reverse_geocoding_job.rb b/app/jobs/reverse_geocoding_job.rb index 27363a24..dc49d2a2 100644 --- a/app/jobs/reverse_geocoding_job.rb +++ b/app/jobs/reverse_geocoding_job.rb @@ -6,7 +6,7 @@ class ReverseGeocodingJob < ApplicationJob def perform(klass, id) return unless REVERSE_GEOCODING_ENABLED - sleep 1 if PHOTON_API_HOST == 'photon.komoot.io' + rate_limit_for_photon_api data_fetcher(klass, id).call end @@ -16,4 +16,10 @@ class ReverseGeocodingJob < ApplicationJob def data_fetcher(klass, id) "ReverseGeocoding::#{klass.pluralize.camelize}::FetchData".constantize.new(id) end + + def rate_limit_for_photon_api + return unless PHOTON_API_HOST == 'photon.komoot.io' + + sleep 1 if PHOTON_API_HOST == 'photon.komoot.io' + end end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 02c0f5ad..f242910b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -24,3 +24,5 @@ end Sidekiq.configure_client do |config| config.redis = { url: ENV['REDIS_URL'] } end + +Sidekiq::Queue['reverse_geocoding'].limit = 1 if PHOTON_API_HOST == 'photon.komoot.io'