-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
amelioration(email): passe les jobs non prioritaire [appelons ça des …
…bulk email], dans la queue de low_priority
- Loading branch information
Martin
committed
Oct 18, 2023
1 parent
dbb68f2
commit b69d4ba
Showing
26 changed files
with
190 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class PriorizedMailDeliveryJob < ActionMailer::MailDeliveryJob | ||
def queue_name | ||
mailer, action_name = @arguments | ||
if mailer.constantize.critical_email?(action_name) | ||
super | ||
else | ||
custom_queue | ||
end | ||
end | ||
|
||
def custom_queue | ||
ENV.fetch('BULK_EMAIL_QUEUE') { Rails.application.config.action_mailer.deliver_later_queue_name } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module PriorityDeliveryConcern | ||
extend ActiveSupport::Concern | ||
included do | ||
self.delivery_job = PriorizedMailDeliveryJob | ||
|
||
def self.critical_email?(action_name) | ||
raise NotImplementedError | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,57 @@ | ||
RSpec.describe AdministrateurMailer, type: :mailer do | ||
let(:procedure) { create(:procedure) } | ||
let(:admin_email) { 'administrateur@email.fr' } | ||
|
||
describe '.notify_procedure_expires_when_termine_forced' do | ||
subject { described_class.notify_procedure_expires_when_termine_forced(admin_email, procedure) } | ||
|
||
it { expect(subject.to).to eq([admin_email]) } | ||
it { expect(subject.subject).to include("La suppression automatique des dossiers a été activée sur la démarche") } | ||
|
||
context 'when perform_later is called' do | ||
let(:custom_queue) { 'low_priority' } | ||
before { ENV['BULK_EMAIL_QUEUE'] = custom_queue } | ||
it 'enqueues email is custom queue for low priority delivery' do | ||
expect { subject.deliver_later }.to have_enqueued_job.on_queue(custom_queue) | ||
end | ||
end | ||
end | ||
|
||
describe '.activate_before_expiration' do | ||
let(:user) { create(:user, reset_password_sent_at: 2.days.ago) } | ||
let(:token) { SecureRandom.hex } | ||
subject { described_class.activate_before_expiration(user, token) } | ||
|
||
context 'without SafeMailer configured' do | ||
subject { described_class.activate_before_expiration(user, token) } | ||
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) } | ||
end | ||
|
||
context 'with SafeMailer configured' do | ||
let(:forced_delivery_method) { :kikoo } | ||
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) } | ||
subject { described_class.activate_before_expiration(user, token) } | ||
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) } | ||
end | ||
|
||
context 'when perform_later is called' do | ||
it 'enqueues email in default queue for high priority delivery' do | ||
expect { subject.deliver_later }.to have_enqueued_job.on_queue(Rails.application.config.action_mailer.deliver_later_queue_name) | ||
end | ||
end | ||
end | ||
|
||
describe '.notify_service_without_siret' do | ||
subject { described_class.notify_service_without_siret(admin_email) } | ||
|
||
it { expect(subject.to).to eq([admin_email]) } | ||
it { expect(subject.subject).to eq("Siret manquant sur un de vos services") } | ||
it { expect(subject.body).to include("un de vos services n'a pas son siret renseigné") } | ||
|
||
context 'when perform_later is called' do | ||
let(:custom_queue) { 'low_priority' } | ||
before { ENV['BULK_EMAIL_QUEUE'] = custom_queue } | ||
it 'enqueues email is custom queue for low priority delivery' do | ||
expect { subject.deliver_later }.to have_enqueued_job.on_queue(custom_queue) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.