Gab Social. All are welcome.
This commit is contained in:
17
app/workers/scheduler/backup_cleanup_scheduler.rb
Normal file
17
app/workers/scheduler/backup_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::BackupCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
old_backups.reorder(nil).find_each(&:destroy!)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def old_backups
|
||||
Backup.where('created_at < ?', 7.days.ago)
|
||||
end
|
||||
end
|
||||
12
app/workers/scheduler/doorkeeper_cleanup_scheduler.rb
Normal file
12
app/workers/scheduler/doorkeeper_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::DoorkeeperCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
25
app/workers/scheduler/email_scheduler.rb
Normal file
25
app/workers/scheduler/email_scheduler.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::EmailScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
FREQUENCY = 7.days.freeze
|
||||
SIGN_IN_OFFSET = 1.day.freeze
|
||||
|
||||
def perform
|
||||
eligible_users.reorder(nil).find_each do |user|
|
||||
next unless user.allows_digest_emails?
|
||||
DigestMailerWorker.perform_async(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def eligible_users
|
||||
User.emailable
|
||||
.where('current_sign_in_at < ?', (FREQUENCY + SIGN_IN_OFFSET).ago)
|
||||
.where('last_emailed_at IS NULL OR last_emailed_at < ?', FREQUENCY.ago)
|
||||
end
|
||||
end
|
||||
61
app/workers/scheduler/feed_cleanup_scheduler.rb
Normal file
61
app/workers/scheduler/feed_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::FeedCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
include Redisable
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
clean_home_feeds!
|
||||
clean_list_feeds!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clean_home_feeds!
|
||||
clean_feeds!(inactive_account_ids, :home)
|
||||
end
|
||||
|
||||
def clean_list_feeds!
|
||||
clean_feeds!(inactive_list_ids, :list)
|
||||
end
|
||||
|
||||
def clean_feeds!(ids, type)
|
||||
reblogged_id_sets = {}
|
||||
|
||||
redis.pipelined do
|
||||
ids.each do |feed_id|
|
||||
redis.del(feed_manager.key(type, feed_id))
|
||||
reblog_key = feed_manager.key(type, feed_id, 'reblogs')
|
||||
# We collect a future for this: we don't block while getting
|
||||
# it, but we can iterate over it later.
|
||||
reblogged_id_sets[feed_id] = redis.zrange(reblog_key, 0, -1)
|
||||
redis.del(reblog_key)
|
||||
end
|
||||
end
|
||||
|
||||
# Remove all of the reblog tracking keys we just removed the
|
||||
# references to.
|
||||
redis.pipelined do
|
||||
reblogged_id_sets.each do |feed_id, future|
|
||||
future.value.each do |reblogged_id|
|
||||
reblog_set_key = feed_manager.key(type, feed_id, "reblogs:#{reblogged_id}")
|
||||
redis.del(reblog_set_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def inactive_account_ids
|
||||
@inactive_account_ids ||= User.confirmed.inactive.pluck(:account_id)
|
||||
end
|
||||
|
||||
def inactive_list_ids
|
||||
List.where(account_id: inactive_account_ids).pluck(:id)
|
||||
end
|
||||
|
||||
def feed_manager
|
||||
FeedManager.instance
|
||||
end
|
||||
end
|
||||
15
app/workers/scheduler/ip_cleanup_scheduler.rb
Normal file
15
app/workers/scheduler/ip_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::IpCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
RETENTION_PERIOD = 1.year
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
time_ago = RETENTION_PERIOD.ago
|
||||
SessionActivation.where('updated_at < ?', time_ago).destroy_all
|
||||
User.where('last_sign_in_at < ?', time_ago).update_all(last_sign_in_ip: nil)
|
||||
end
|
||||
end
|
||||
17
app/workers/scheduler/media_cleanup_scheduler.rb
Normal file
17
app/workers/scheduler/media_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::MediaCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
unattached_media.find_each(&:destroy)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unattached_media
|
||||
MediaAttachment.reorder(nil).unattached.where('created_at < ?', 1.day.ago)
|
||||
end
|
||||
end
|
||||
11
app/workers/scheduler/pghero_scheduler.rb
Normal file
11
app/workers/scheduler/pghero_scheduler.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::PgheroScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
PgHero.capture_space_stats
|
||||
end
|
||||
end
|
||||
19
app/workers/scheduler/scheduled_statuses_scheduler.rb
Normal file
19
app/workers/scheduler/scheduled_statuses_scheduler.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::ScheduledStatusesScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
due_statuses.find_each do |scheduled_status|
|
||||
PublishScheduledStatusWorker.perform_at(scheduled_status.scheduled_at, scheduled_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def due_statuses
|
||||
ScheduledStatus.where('scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
|
||||
end
|
||||
end
|
||||
11
app/workers/scheduler/subscriptions_cleanup_scheduler.rb
Normal file
11
app/workers/scheduler/subscriptions_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::SubscriptionsCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
Subscription.expired.in_batches.delete_all
|
||||
end
|
||||
end
|
||||
17
app/workers/scheduler/subscriptions_scheduler.rb
Normal file
17
app/workers/scheduler/subscriptions_scheduler.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::SubscriptionsScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
Pubsubhubbub::SubscribeWorker.push_bulk(expiring_accounts.pluck(:id))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expiring_accounts
|
||||
Account.expiring(1.day.from_now).partitioned
|
||||
end
|
||||
end
|
||||
14
app/workers/scheduler/user_cleanup_scheduler.rb
Normal file
14
app/workers/scheduler/user_cleanup_scheduler.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::UserCleanupScheduler
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options unique: :until_executed, retry: 0
|
||||
|
||||
def perform
|
||||
User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).reorder(nil).find_in_batches do |batch|
|
||||
Account.where(id: batch.map(&:account_id)).delete_all
|
||||
User.where(id: batch.map(&:id)).delete_all
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user