dawarich/app/jobs/users/mailer_sending_job.rb
Evgenii Burmakin ce8a7cd4ef
Implement some performance improvements and caching for various featu… (#2133)
* Implement some performance improvements and caching for various features.

* Fix failing tests

* Implement routes behaviour in map v2 to match map v1

* Fix route highlighting

* Add fallbacks when retrieving full route features to handle cases where source data access methods vary.

* Fix some e2e tests
2026-01-07 19:48:14 +01:00

33 lines
808 B
Ruby

# 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)
params = { user: user }.merge(options)
UsersMailer.with(params).public_send(email_type).deliver_later
rescue ActiveRecord::RecordNotFound
ExceptionReporter.call(
'Users::MailerSendingJob',
"User with ID #{user_id} not found. Skipping #{email_type} email."
)
end
private
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
end