Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Periodically remove expired PuSH subscribers (mastodon#4654)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored and abcang committed Aug 22, 2017
1 parent 23d5371 commit b9aaaff
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Subscription < ApplicationRecord

scope :confirmed, -> { where(confirmed: true) }
scope :future_expiration, -> { where(arel_table[:expires_at].gt(Time.now.utc)) }
scope :expired, -> { where(arel_table[:expires_at].lt(Time.now.utc)) }
scope :active, -> { confirmed.future_expiration }

def lease_seconds=(value)
Expand Down
2 changes: 0 additions & 2 deletions app/workers/scheduler/feed_cleanup_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Scheduler::FeedCleanupScheduler
include Sidekiq::Worker

def perform
logger.info 'Cleaning out home feeds of inactive users'

redis.pipelined do
inactive_users.pluck(:account_id).each do |account_id|
redis.del(FeedManager.instance.key(:home, account_id))
Expand Down
1 change: 0 additions & 1 deletion app/workers/scheduler/media_cleanup_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Scheduler::MediaCleanupScheduler
include Sidekiq::Worker

def perform
logger.info 'Cleaning out unattached media attachments'
unattached_media.find_each(&:destroy)
end

Expand Down
11 changes: 11 additions & 0 deletions app/workers/scheduler/subscriptions_cleanup_scheduler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'sidekiq-scheduler'

class Scheduler::SubscriptionsCleanupScheduler
include Sidekiq::Worker

def perform
Subscription.expired.in_batches.delete_all
end
end
1 change: 0 additions & 1 deletion app/workers/scheduler/subscriptions_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Scheduler::SubscriptionsScheduler
include Sidekiq::Worker

def perform
logger.info 'Queueing PuSH re-subscriptions'
Pubsubhubbub::SubscribeWorker.push_bulk(expiring_accounts.pluck(:id))
end

Expand Down
3 changes: 3 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
doorkeeper_cleanup_scheduler:
cron: '1 1 * * 0'
class: Scheduler::DoorkeeperCleanupScheduler
subscriptions_cleanup_scheduler:
cron: '2 2 * * 0'
class: Scheduler::SubscriptionsCleanupScheduler
delete_elasticsearch_documents_worker:
cron: '*/2 * * * *'
class: Scheduler::DeleteElasticsearchDocumentsWorker
Expand Down

0 comments on commit b9aaaff

Please sign in to comment.