class Scheduler::EmailScheduler
include Sidekiq::Worker
- sidekiq_options unique: :until_executed
+ sidekiq_options retry: 0
+
+ FREQUENCY = 7.days.freeze
+ SIGN_IN_OFFSET = 1.day.freeze
def perform
eligible_users.reorder(nil).find_each do |user|
private
def eligible_users
- User.confirmed
- .joins(:account)
- .where(accounts: { silenced: false, suspended: false })
- .where(disabled: false)
- .where('current_sign_in_at < ?', 20.days.ago)
- .where('last_emailed_at IS NULL OR last_emailed_at < ?', 20.days.ago)
+ User.emailable
+ .where('current_sign_in_at < ?', (FREQUENCY + SIGN_IN_OFFSET).ago)
+ .where('last_emailed_at IS NULL OR last_emailed_at < ?', FREQUENCY.ago)
end
end