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

  1. # frozen_string_literal: true
  2. class Scheduler::EmailScheduler
  3. include Sidekiq::Worker
  4. sidekiq_options lock: :until_executed, retry: 0
  5. FREQUENCY = 7.days.freeze
  6. SIGN_IN_OFFSET = 1.day.freeze
  7. def perform
  8. eligible_users.reorder(nil).find_each do |user|
  9. next unless user.allows_digest_emails?
  10. DigestMailerWorker.perform_async(user.id)
  11. end
  12. end
  13. private
  14. def eligible_users
  15. User.emailable
  16. .where('current_sign_in_at < ?', (FREQUENCY + SIGN_IN_OFFSET).ago)
  17. .where('last_emailed_at IS NULL OR last_emailed_at < ?', FREQUENCY.ago)
  18. end
  19. end