-
-
Notifications
You must be signed in to change notification settings - Fork 40
Custom Mailer Job
Janko Marohnić edited this page Oct 18, 2024
·
1 revision
If you're using a background processing library without an Active Job adapter, or a 3rd-party service for sending transactional emails, the default two-phase setup might not be suitable.
In this case, instead of overriding #create_*_email
and #send_email
, override the #send_*_email
methods instead, which are required to send the email immediately. For example:
# app/jobs/rodauth_mailer_job.rb
class RodauthMailerJob
include Sidekiq::Job
def perform(name, *args)
email = RodauthMailer.public_send(name, *args)
email.deliver_now
end
end
# app/misc/rodauth_main.rb
class RodauthMain < Rodauth::Rails::Auth
configure do
# ...
# use `#send_*_email` method to be able to immediately enqueue email delivery
send_reset_password_email do
enqueue_email(:reset_password, account_id, reset_password_key_value)
end
# ...
end
private
# define custom method for enqueuing email delivery using our job
def enqueue_email(name, *args)
db.after_commit do
RodauthMailerJob.perform_async(name, *args)
end
end
end