From e89e976e924f558d13893726b3edda7b428988fd Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 15 Mar 2021 11:17:43 +0100 Subject: [PATCH] Fix configuration for sidekiq-unique-jobs after 7.x upgrade (#15908) Remove locks from scheduled jobs --- .../scheduler/backup_cleanup_scheduler.rb | 2 +- .../scheduler/doorkeeper_cleanup_scheduler.rb | 2 +- app/workers/scheduler/email_scheduler.rb | 2 +- .../scheduler/feed_cleanup_scheduler.rb | 2 +- .../scheduler/instance_refresh_scheduler.rb | 2 +- app/workers/scheduler/ip_cleanup_scheduler.rb | 2 +- .../scheduler/media_cleanup_scheduler.rb | 2 +- app/workers/scheduler/pghero_scheduler.rb | 2 +- .../scheduler/scheduled_statuses_scheduler.rb | 2 +- .../scheduler/trending_tags_scheduler.rb | 2 +- .../scheduler/user_cleanup_scheduler.rb | 2 +- config/initializers/sidekiq.rb | 22 ++++++++++++++++--- 12 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/workers/scheduler/backup_cleanup_scheduler.rb b/app/workers/scheduler/backup_cleanup_scheduler.rb index d69ca2556a..85d5312c0a 100644 --- a/app/workers/scheduler/backup_cleanup_scheduler.rb +++ b/app/workers/scheduler/backup_cleanup_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::BackupCleanupScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform old_backups.reorder(nil).find_each(&:destroy!) diff --git a/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb b/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb index bb9dd49ca2..9303a352fb 100644 --- a/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb +++ b/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::DoorkeeperCleanupScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform Doorkeeper::AccessToken.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all diff --git a/app/workers/scheduler/email_scheduler.rb b/app/workers/scheduler/email_scheduler.rb index 9a73555248..c052f2fce0 100644 --- a/app/workers/scheduler/email_scheduler.rb +++ b/app/workers/scheduler/email_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::EmailScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 FREQUENCY = 7.days.freeze SIGN_IN_OFFSET = 1.day.freeze diff --git a/app/workers/scheduler/feed_cleanup_scheduler.rb b/app/workers/scheduler/feed_cleanup_scheduler.rb index 42b29f4eca..aa0cc8b8df 100644 --- a/app/workers/scheduler/feed_cleanup_scheduler.rb +++ b/app/workers/scheduler/feed_cleanup_scheduler.rb @@ -4,7 +4,7 @@ class Scheduler::FeedCleanupScheduler include Sidekiq::Worker include Redisable - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform clean_home_feeds! diff --git a/app/workers/scheduler/instance_refresh_scheduler.rb b/app/workers/scheduler/instance_refresh_scheduler.rb index 917404becc..2af5f38554 100644 --- a/app/workers/scheduler/instance_refresh_scheduler.rb +++ b/app/workers/scheduler/instance_refresh_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::InstanceRefreshScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform Instance.refresh diff --git a/app/workers/scheduler/ip_cleanup_scheduler.rb b/app/workers/scheduler/ip_cleanup_scheduler.rb index 853f20e251..df7e6ad56a 100644 --- a/app/workers/scheduler/ip_cleanup_scheduler.rb +++ b/app/workers/scheduler/ip_cleanup_scheduler.rb @@ -5,7 +5,7 @@ class Scheduler::IpCleanupScheduler IP_RETENTION_PERIOD = 1.year.freeze - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform clean_ip_columns! diff --git a/app/workers/scheduler/media_cleanup_scheduler.rb b/app/workers/scheduler/media_cleanup_scheduler.rb index 671ebf6e02..24d30a6be5 100644 --- a/app/workers/scheduler/media_cleanup_scheduler.rb +++ b/app/workers/scheduler/media_cleanup_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::MediaCleanupScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform unattached_media.find_each(&:destroy) diff --git a/app/workers/scheduler/pghero_scheduler.rb b/app/workers/scheduler/pghero_scheduler.rb index cf55700486..a756b13b93 100644 --- a/app/workers/scheduler/pghero_scheduler.rb +++ b/app/workers/scheduler/pghero_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::PgheroScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform PgHero.capture_space_stats diff --git a/app/workers/scheduler/scheduled_statuses_scheduler.rb b/app/workers/scheduler/scheduled_statuses_scheduler.rb index 25df3c07de..3bf6300b3c 100644 --- a/app/workers/scheduler/scheduled_statuses_scheduler.rb +++ b/app/workers/scheduler/scheduled_statuses_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::ScheduledStatusesScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform publish_scheduled_statuses! diff --git a/app/workers/scheduler/trending_tags_scheduler.rb b/app/workers/scheduler/trending_tags_scheduler.rb index e9891424e0..94d76d010d 100644 --- a/app/workers/scheduler/trending_tags_scheduler.rb +++ b/app/workers/scheduler/trending_tags_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::TrendingTagsScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform TrendingTags.update! if Setting.trends diff --git a/app/workers/scheduler/user_cleanup_scheduler.rb b/app/workers/scheduler/user_cleanup_scheduler.rb index 8571b59e14..be0c4277da 100644 --- a/app/workers/scheduler/user_cleanup_scheduler.rb +++ b/app/workers/scheduler/user_cleanup_scheduler.rb @@ -3,7 +3,7 @@ class Scheduler::UserCleanupScheduler include Sidekiq::Worker - sidekiq_options lock: :until_executed, retry: 0 + sidekiq_options retry: 0 def perform clean_unconfirmed_accounts! diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index f2733562fb..9d348ddd08 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -14,14 +14,30 @@ Sidekiq.configure_server do |config| chain.add SidekiqErrorHandler end - config.death_handlers << lambda do |job, _ex| - digest = job['lock_digest'] - SidekiqUniqueJobs::Digests.delete_by_digest(digest) if digest + config.server_middleware do |chain| + chain.add SidekiqUniqueJobs::Middleware::Server end + + config.client_middleware do |chain| + chain.add SidekiqUniqueJobs::Middleware::Client + end + + SidekiqUniqueJobs::Server.configure(config) end Sidekiq.configure_client do |config| config.redis = redis_params + + config.client_middleware do |chain| + chain.add SidekiqUniqueJobs::Middleware::Client + end end Sidekiq.logger.level = ::Logger.const_get(ENV.fetch('RAILS_LOG_LEVEL', 'info').upcase.to_s) + +SidekiqUniqueJobs.configure do |config| + config.reaper = :ruby + config.reaper_count = 1000 + config.reaper_interval = 600 + config.reaper_timeout = 150 +end