Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 9014367

Browse files
authored
Fix background jobs not using locks like they are supposed to (mastodon#13361)
Also: - Fix locks not being removed when jobs go to the dead job queue - Add UI for managing locks to the Sidekiq dashboard - Remove unused Sidekiq workers Fix mastodon#13349
1 parent 1fb9203 commit 9014367

34 files changed

+23
-152
lines changed

app/workers/activitypub/distribute_poll_update_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ActivityPub::DistributePollUpdateWorker
44
include Sidekiq::Worker
55
include Payloadable
66

7-
sidekiq_options queue: 'push', unique: :until_executed, retry: 0
7+
sidekiq_options queue: 'push', lock: :until_executed, retry: 0
88

99
def perform(status_id)
1010
@status = Status.find(status_id)

app/workers/activitypub/synchronize_featured_collection_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class ActivityPub::SynchronizeFeaturedCollectionWorker
44
include Sidekiq::Worker
55

6-
sidekiq_options queue: 'pull', unique: :until_executed
6+
sidekiq_options queue: 'pull', lock: :until_executed
77

88
def perform(account_id)
99
ActivityPub::FetchFeaturedCollectionService.new.call(Account.find(account_id))

app/workers/after_remote_follow_request_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/after_remote_follow_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/notification_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/poll_expiration_notify_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class PollExpirationNotifyWorker
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed
6+
sidekiq_options lock: :until_executed
77

88
def perform(poll_id)
99
poll = Poll.find(poll_id)

app/workers/processing_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/publish_scheduled_status_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class PublishScheduledStatusWorker
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed
6+
sidekiq_options lock: :until_executed
77

88
def perform(scheduled_status_id)
99
scheduled_status = ScheduledStatus.find(scheduled_status_id)

app/workers/pubsubhubbub/confirmation_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/pubsubhubbub/delivery_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/pubsubhubbub/distribution_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/pubsubhubbub/raw_distribution_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/pubsubhubbub/subscribe_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/pubsubhubbub/unsubscribe_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/regeneration_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class RegenerationWorker
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed
6+
sidekiq_options lock: :until_executed
77

88
def perform(account_id, _ = :home)
99
account = Account.find(account_id)

app/workers/remote_profile_update_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/resolve_account_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class ResolveAccountWorker
44
include Sidekiq::Worker
55

6-
sidekiq_options queue: 'pull', unique: :until_executed
6+
sidekiq_options queue: 'pull', lock: :until_executed
77

88
def perform(uri)
99
ResolveAccountService.new.call(uri)

app/workers/salmon_worker.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/scheduler/backup_cleanup_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::BackupCleanupScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
old_backups.reorder(nil).find_each(&:destroy!)

app/workers/scheduler/doorkeeper_cleanup_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::DoorkeeperCleanupScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
Doorkeeper::AccessToken.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all

app/workers/scheduler/email_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::EmailScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
FREQUENCY = 7.days.freeze
99
SIGN_IN_OFFSET = 1.day.freeze

app/workers/scheduler/feed_cleanup_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Scheduler::FeedCleanupScheduler
44
include Sidekiq::Worker
55
include Redisable
66

7-
sidekiq_options unique: :until_executed, retry: 0
7+
sidekiq_options lock: :until_executed, retry: 0
88

99
def perform
1010
clean_home_feeds!

app/workers/scheduler/ip_cleanup_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Scheduler::IpCleanupScheduler
55

66
RETENTION_PERIOD = 1.year
77

8-
sidekiq_options unique: :until_executed, retry: 0
8+
sidekiq_options lock: :until_executed, retry: 0
99

1010
def perform
1111
time_ago = RETENTION_PERIOD.ago

app/workers/scheduler/media_cleanup_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::MediaCleanupScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
unattached_media.find_each(&:destroy)

app/workers/scheduler/pghero_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::PgheroScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
PgHero.capture_space_stats

app/workers/scheduler/scheduled_statuses_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::ScheduledStatusesScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
publish_scheduled_statuses!

app/workers/scheduler/subscriptions_cleanup_scheduler.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/scheduler/subscriptions_scheduler.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/workers/scheduler/trending_tags_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::TrendingTagsScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
TrendingTags.update! if Setting.trends

app/workers/scheduler/user_cleanup_scheduler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Scheduler::UserCleanupScheduler
44
include Sidekiq::Worker
55

6-
sidekiq_options unique: :until_executed, retry: 0
6+
sidekiq_options lock: :until_executed, retry: 0
77

88
def perform
99
User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).reorder(nil).find_in_batches do |batch|

app/workers/verify_account_links_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class VerifyAccountLinksWorker
44
include Sidekiq::Worker
55

6-
sidekiq_options queue: 'pull', retry: false, unique: :until_executed
6+
sidekiq_options queue: 'pull', retry: false, lock: :until_executed
77

88
def perform(account_id)
99
account = Account.find(account_id)

config/initializers/sidekiq.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
config.server_middleware do |chain|
1414
chain.add SidekiqErrorHandler
1515
end
16+
17+
config.death_handlers << lambda do |job, _ex|
18+
digest = job['lock_digest']
19+
SidekiqUniqueJobs::Digests.delete_by_digest(digest) if digest
20+
end
1621
end
1722

1823
Sidekiq.configure_client do |config|

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'sidekiq/web'
3+
require 'sidekiq_unique_jobs/web'
44
require 'sidekiq-scheduler/web'
55

66
Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_key_base]

spec/services/import_service_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191

9292
let(:csv) { attachment_fixture('mute-imports.txt') }
9393

94-
before do
95-
allow(NotificationWorker).to receive(:perform_async)
96-
end
97-
9894
describe 'when no accounts are followed' do
9995
let(:import) { Import.create(account: account, type: 'following', data: csv) }
10096
it 'follows the listed accounts, including boosts' do
@@ -135,10 +131,6 @@
135131

136132
let(:csv) { attachment_fixture('new-following-imports.txt') }
137133

138-
before do
139-
allow(NotificationWorker).to receive(:perform_async)
140-
end
141-
142134
describe 'when no accounts are followed' do
143135
let(:import) { Import.create(account: account, type: 'following', data: csv) }
144136
it 'follows the listed accounts, respecting boosts' do

0 commit comments

Comments
 (0)