闭社主体 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.

23 lines
565 B

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