diaspora/app/workers/remove_old_user.rb
Jason Robinson 69c3566958 Maintenance feature to remove old users
Add Sidetiq webview to the Sidekiq monitoring panel

Add rake task maintenance:queue_users_for_removal
This basically just triggers an immediate run of the normal maintenance remove old users functionality that is normally (if enabled) scheduled to run once a day via sidetiq

Add extra safety when checking for user removal due to inactivity.
Now also user.last_seen will also be checked to make sure a user will not be removed in the event that the Devise rememember me login functionality has stopped the users remove_after timestamp from being removed.

Add initializer for maintenance job.
Add warning about mail being disabled if remove_old_users maintenance is enabled.
2014-10-16 22:53:08 +03:00

27 lines
No EOL
977 B
Ruby

# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Workers
class RemoveOldUser < Base
sidekiq_options queue: :maintenance
def safe_remove_after
# extra safety time to compare in addition to remove_after
Time.now-
(AppConfig.settings.maintenance.remove_old_users.after_days.to_i).days-
(AppConfig.settings.maintenance.remove_old_users.warn_days.to_i).days
end
def perform(user_id)
# if user has been flagged as to be removed (see settings.maintenance.remove_old_users)
# and hasn't logged in since that flag has been set, we remove the user
if AppConfig.settings.maintenance.remove_old_users.enable?
user = User.find(user_id)
if user.remove_after < Time.now and user.last_seen < self.safe_remove_after
user.close_account!
end
end
end
end
end