The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
621 B

  1. # frozen_string_literal: true
  2. class Scheduler::EmailScheduler
  3. include Sidekiq::Worker
  4. sidekiq_options unique: :until_executed
  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