docbrown/app/workers/follows/send_email_notification_worker.rb
Lud df042d6b0b Refactors ActiveJob to SidekiqWorker: Follows::SendEmailNotificationWorker (#5322) [deploy]
* Refactors ActiveJob to SidekiqWorker: Follows::SendEmailNotificationWorker
* improves naming of User#receives_follower_email_notifications?
* adjust expect count for spec SendEmailNotificationWorker
2020-01-02 13:35:09 -05:00

17 lines
652 B
Ruby

module Follows
class SendEmailNotificationWorker
include Sidekiq::Worker
sidekiq_options queue: :mailers, retry: 10
def perform(follow_id, mailer = NotifyMailer.name)
follow = Follow.find_by(id: follow_id, followable_type: "User")
return unless follow&.followable.present? && follow.followable.receives_follower_email_notifications?
return if EmailMessage.where(user_id: follow.followable_id).
where("sent_at > ?", rand(15..35).hours.ago).
where("subject LIKE ?", "%#{NotifyMailer::SUBJECTS[:new_follower_email]}").exists?
mailer.constantize.new_follower_email(follow).deliver
end
end
end