Class: Workers::QueueUsersForRemoval

Inherits:
Base
  • Object
show all
Defined in:
app/workers/queue_users_for_removal.rb

Instance Method Summary collapse

Instance Method Details

#performObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/workers/queue_users_for_removal.rb', line 11

def perform
  # Queue users for removal due to inactivity
  if AppConfig.settings.maintenance.remove_old_users.enable?
    users = User.where("last_seen < ? and locked_at is null and remove_after is null", 
      Time.now - (AppConfig.settings.maintenance.remove_old_users.after_days.to_i).days)
      .order(:last_seen)
      .limit(AppConfig.settings.maintenance.remove_old_users.limit_removals_to_per_day)

    # deliver to be closed emails to account holders
    # and queue accounts for closing to sidekiq
    # for those who have not signed in, skip warning and queue removal
    # in +1 days
    users.each do |user|
      if user. > 0
        remove_at = Time.now + AppConfig.settings.maintenance.remove_old_users.warn_days.to_i.days
      else
        remove_at = Time.now
      end
      user.flag_for_removal(remove_at)
      if user. > 0
        # send a warning
        Maintenance.(user).deliver_now
      end
      Workers::RemoveOldUser.perform_in(remove_at+1.day, user.id)
    end
  end
end