Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodically remove expired PuSH subscribers #4654

Merged
merged 1 commit into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing it immediately seems maybe bad depending on when people set their renewal times to be? Something like expires_at.lt(Time.now.utc - 7.days) or 14 days is probably Good Enough and allows for a little bit of leniency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nightpool This matters not. Renewing is the same as subscribing from scratch. The secret is fresh, etc. There is virtually no reason why you'd want to keep a particular record beyond its expiration date. Plus the removal worker runs only once a day.

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,3 +21,6 @@
user_cleanup_scheduler:
cron: '4 5 * * *'
class: Scheduler::UserCleanupScheduler
subscriptions_cleanup_scheduler:
cron: '2 2 * * 0'
class: Scheduler::SubscriptionsCleanupScheduler