Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Keep scheduler jobs unique until they're done (mastodon#8287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored and kyori19 committed Sep 17, 2018
1 parent c620edc commit 6b8a0c1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/workers/scheduler/backup_cleanup_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::BackupCleanupScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
old_backups.find_each(&:destroy!)
end
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/doorkeeper_cleanup_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::DoorkeeperCleanupScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
Doorkeeper::AccessToken.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all
Doorkeeper::AccessGrant.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/email_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::EmailScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
eligible_users.find_each do |user|
next unless user.allows_digest_emails?
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/feed_cleanup_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::FeedCleanupScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
clean_home_feeds!
clean_list_feeds!
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/ip_cleanup_scheduler.rb
Expand Up @@ -5,6 +5,8 @@ class Scheduler::IpCleanupScheduler

RETENTION_PERIOD = 1.year

sidekiq_options unique: :until_executed

def perform
time_ago = RETENTION_PERIOD.ago
SessionActivation.where('updated_at < ?', time_ago).destroy_all
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/media_cleanup_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::MediaCleanupScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
unattached_media.find_each(&:destroy)
end
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/subscriptions_cleanup_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::SubscriptionsCleanupScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
Subscription.expired.in_batches.delete_all
end
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/subscriptions_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::SubscriptionsScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
Pubsubhubbub::SubscribeWorker.push_bulk(expiring_accounts.pluck(:id))
end
Expand Down
2 changes: 2 additions & 0 deletions app/workers/scheduler/user_cleanup_scheduler.rb
Expand Up @@ -3,6 +3,8 @@
class Scheduler::UserCleanupScheduler
include Sidekiq::Worker

sidekiq_options unique: :until_executed

def perform
User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).find_in_batches do |batch|
Account.where(id: batch.map(&:account_id)).delete_all
Expand Down

0 comments on commit 6b8a0c1

Please sign in to comment.