digest_mailer_worker.rb 460 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class DigestMailerWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'mailers'
  5. attr_reader :user
  6. def perform(user_id)
  7. @user = User.find(user_id)
  8. deliver_digest if user_receives_digest?
  9. end
  10. private
  11. def deliver_digest
  12. NotificationMailer.digest(user.account).deliver_now!
  13. user.touch(:last_emailed_at)
  14. end
  15. def user_receives_digest?
  16. user.settings.notification_emails['digest']
  17. end
  18. end