闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
631 B

  1. # frozen_string_literal: true
  2. class Scheduler::EmailScheduler
  3. include Sidekiq::Worker
  4. sidekiq_options unique: :until_executed, retry: 0
  5. def perform
  6. eligible_users.reorder(nil).find_each do |user|
  7. next unless user.allows_digest_emails?
  8. DigestMailerWorker.perform_async(user.id)
  9. end
  10. end
  11. private
  12. def eligible_users
  13. User.confirmed
  14. .joins(:account)
  15. .where(accounts: { silenced: false, suspended: false })
  16. .where(disabled: false)
  17. .where('current_sign_in_at < ?', 20.days.ago)
  18. .where('last_emailed_at IS NULL OR last_emailed_at < ?', 20.days.ago)
  19. end
  20. end