Skip to content

Commit

Permalink
Merge pull request #2155 from betagouv/more-jobs-queues
Browse files Browse the repository at this point in the history
Add job workers
  • Loading branch information
n-b authored Mar 7, 2022
2 parents d198f7c + fdcef71 commit eb9de96
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
self.deliver_later_queue_name = :mailers

prepend IcsMultipartAttached

default from: "[email protected]"
Expand Down
2 changes: 2 additions & 0 deletions app/mailers/custom_devise_mailer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/services/notifiers/rdv_upcoming_reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/sms/application_sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions config/initializers/delayed_job.rb
Original file line number Diff line number Diff line change
@@ -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 }
}

0 comments on commit eb9de96

Please sign in to comment.