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

Commit

Permalink
Merge pull request mastodon#614 from pixiv/move_clean_up_of_unconfirm…
Browse files Browse the repository at this point in the history
…ed_users

Move clean up of unconfirmed users to sidekiq-scheduler (mastodon#4336)
  • Loading branch information
abcang committed Aug 22, 2017
2 parents e23d350 + 429b7b2 commit fd859aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
15 changes: 15 additions & 0 deletions app/workers/scheduler/user_cleanup_scheduler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'sidekiq-scheduler'

class Scheduler::UserCleanupScheduler
include Sidekiq::Worker

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
User.where(id: batch.map(&:id)).delete_all
OauthAuthentication.where(user_id: batch.map(&:id)).delete_all
InitialPasswordUsage.where(user_id: batch.map(&:id)).delete_all
end
end
end
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
user_cleanup_scheduler:
cron: '4 5 * * *'
class: Scheduler::UserCleanupScheduler
delete_elasticsearch_documents_worker:
cron: '*/2 * * * *'
class: Scheduler::DeleteElasticsearchDocumentsWorker
Expand Down
26 changes: 6 additions & 20 deletions lib/tasks/mastodon.rake
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# frozen_string_literal: true

namespace :mastodon do
desc 'Execute daily tasks'
desc 'Execute daily tasks (deprecated)'
task :daily do
%w(
mastodon:feeds:clear
mastodon:media:clear
mastodon:users:clear
mastodon:push:refresh
).each do |task|
puts "Starting #{task} at #{Time.now.utc}"
Rake::Task[task].invoke
end
puts "Completed daily tasks at #{Time.now.utc}"
# No-op
# All of these tasks are now executed via sidekiq-scheduler
end

desc 'Turn a user into an admin, identified by the USERNAME environment variable'
Expand Down Expand Up @@ -141,16 +133,10 @@ namespace :mastodon do
end

namespace :users do
desc 'Clear out unconfirmed users'
desc 'Clear out unconfirmed users (deprecated)'
task clear: :environment do
# Users that never confirmed e-mail never signed in, means they
# only have a user record and an avatar record, with no files uploaded
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
User.where(id: batch.map(&:id)).delete_all
OauthAuthentication.where(user_id: batch.map(&:id)).delete_all
InitialPasswordUsage.where(user_id: batch.map(&:id)).delete_all
end
# No-op
# This task is now executed via sidekiq-scheduler
end

desc 'List all admin users'
Expand Down

0 comments on commit fd859aa

Please sign in to comment.