dawarich/app/jobs/users/mailer_sending_job.rb

34 lines
808 B
Ruby
Raw Normal View History

2025-08-13 14:25:48 -04:00
# frozen_string_literal: true
class Users::MailerSendingJob < ApplicationJob
queue_as :mailers
def perform(user_id, email_type, **options)
user = User.find(user_id)
return if should_skip_email?(user, email_type)
2025-08-19 12:55:22 -04:00
2025-08-13 14:25:48 -04:00
params = { user: user }.merge(options)
UsersMailer.with(params).public_send(email_type).deliver_later
2025-09-10 18:19:34 -04:00
rescue ActiveRecord::RecordNotFound
2025-09-13 09:58:36 -04:00
ExceptionReporter.call(
'Users::MailerSendingJob',
"User with ID #{user_id} not found. Skipping #{email_type} email."
)
2025-08-13 14:25:48 -04:00
end
2025-08-19 12:55:22 -04:00
private
2025-09-05 13:39:50 -04:00
def should_skip_email?(user, email_type)
case email_type.to_s
when 'trial_expires_soon', 'trial_expired'
user.active?
when 'post_trial_reminder_early', 'post_trial_reminder_late'
user.active? || !user.trial?
else
false
end
end
2025-08-13 14:25:48 -04:00
end