From fdcef717d569296c09468652ad6dbc591f678243 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 14 Feb 2022 18:13:19 +0100 Subject: [PATCH] Specify lower priority for reminder notifications --- app/mailers/application_mailer.rb | 2 ++ app/mailers/custom_devise_mailer.rb | 2 ++ app/services/notifiers/rdv_upcoming_reminder.rb | 4 ++-- app/sms/application_sms.rb | 4 ++-- config/initializers/delayed_job.rb | 16 ++++++++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 config/initializers/delayed_job.rb diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index d9b0870f41..252b3768cc 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ApplicationMailer < ActionMailer::Base + self.deliver_later_queue_name = :mailers + prepend IcsMultipartAttached default from: "contact@rdv-solidarites.fr" diff --git a/app/mailers/custom_devise_mailer.rb b/app/mailers/custom_devise_mailer.rb index ed36210b18..d6f7c56141 100644 --- a/app/mailers/custom_devise_mailer.rb +++ b/app/mailers/custom_devise_mailer.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class CustomDeviseMailer < Devise::Mailer + self.deliver_later_queue_name = :devise + include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url` helper :application diff --git a/app/services/notifiers/rdv_upcoming_reminder.rb b/app/services/notifiers/rdv_upcoming_reminder.rb index a75db018a3..4f7caaaec5 100644 --- a/app/services/notifiers/rdv_upcoming_reminder.rb +++ b/app/services/notifiers/rdv_upcoming_reminder.rb @@ -8,12 +8,12 @@ def rdvs_users_to_notify end def notify_user_by_mail(user) - Users::RdvMailer.rdv_upcoming_reminder(@rdv.payload(nil, user), user).deliver_later + Users::RdvMailer.rdv_upcoming_reminder(@rdv.payload(nil, user), user).deliver_later(queue: :mailers_low) @rdv.events.create!(event_type: RdvEvent::TYPE_NOTIFICATION_MAIL, event_name: :upcoming_reminder) end def notify_user_by_sms(user) - Users::RdvSms.rdv_upcoming_reminder(@rdv, user).deliver_later + Users::RdvSms.rdv_upcoming_reminder(@rdv, user).deliver_later(queue: :sms_low) @rdv.events.create!(event_type: RdvEvent::TYPE_NOTIFICATION_SMS, event_name: :upcoming_reminder) end end diff --git a/app/sms/application_sms.rb b/app/sms/application_sms.rb index ebd372ae33..e37aca0597 100644 --- a/app/sms/application_sms.rb +++ b/app/sms/application_sms.rb @@ -47,10 +47,10 @@ def respond_to_missing?(symbol, include_all = false) # Enqueue a DelayedJob with the sms # Note: the stored parameter in the delayed_jobs table is the ApplicationSms instance. - def deliver_later + def deliver_later(queue: :sms) raise InvalidMobilePhoneNumberError, "#{phone_number} is not a valid mobile phone number" unless PhoneNumberValidation.number_is_mobile?(phone_number) - SmsSender.delay(queue: :sms).perform_with(phone_number, content, tags, provider, key) + SmsSender.delay(queue: queue).perform_with(phone_number, content, tags, provider, key) end private diff --git a/config/initializers/delayed_job.rb b/config/initializers/delayed_job.rb new file mode 100644 index 0000000000..7ef48f25f2 --- /dev/null +++ b/config/initializers/delayed_job.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# We declare the following queues in the code: +# :cron used in CronJob +# :webhook used in WebhookJob +# :mailers used in ApplicationMailer +# :devise used in CustomDeviseMailer +# :sms used in ApplicationSms +# +# Additionally, we declare the two following queues for lower priority jobs (e.g. Reminders) +# :mailers_low +# :sms_low +Delayed::Worker.queue_attributes = { + mailers_low: { priority: 10 }, # Higher numbers have lower priority. + sms_low: { priority: 10 } +}