about summary refs log tree commit diff
path: root/app/workers/scheduler/defang_scheduler.rb
blob: 7476cc93344d7d60e1c79b65c5bdbf10f30ee179 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

class Scheduler::DefangScheduler
  include Sidekiq::Worker
  include ServiceAccountHelper

  def perform
    User.where(defanged: false, last_fanged_at: nil).or(User.where('last_fanged_at <= ?', 15.minutes.ago)).find_each do |user|
      user.defang!
      next unless user&.account.present?

      service_dm('announcements', user.account, "You are no longer in #{user.role} mode.", footer: 'auto-defang')
    end
  end
end