Merge pull request #1462 from betagouv/fix-1454

[Fix #1454] Send weekly overview emails async, overview param is not …
This commit is contained in:
Mathieu Magnin 2018-02-22 15:15:58 +01:00 committed by GitHub
commit 58ded37404
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 6 deletions

View file

@ -523,7 +523,7 @@ Performance/FlatMap:
Enabled: true Enabled: true
Performance/HashEachMethods: Performance/HashEachMethods:
Enabled: true Enabled: false
Performance/LstripRstrip: Performance/LstripRstrip:
Enabled: true Enabled: true

View file

@ -6,4 +6,8 @@ class ApplicationJob < ActiveJob::Base
after_perform do |job| after_perform do |job|
Rails.logger.info("#{job.class.name} ended at #{Time.now}") Rails.logger.info("#{job.class.name} ended at #{Time.now}")
end end
def error(job, exception)
Raven.capture_exception(exception)
end
end end

View file

@ -7,7 +7,7 @@ class WeeklyOverviewJob < ApplicationJob
Gestionnaire.all Gestionnaire.all
.map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] } .map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] }
.reject { |_, overview| overview.nil? } .reject { |_, overview| overview.nil? }
.each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now } .each { |gestionnaire, _| GestionnaireMailer.last_week_overview(gestionnaire).deliver_later }
end end
end end
end end

View file

@ -5,8 +5,9 @@ class GestionnaireMailer < ApplicationMailer
send_mail email, password, "Vous avez été nommé accompagnateur sur la plateforme TPS" send_mail email, password, "Vous avez été nommé accompagnateur sur la plateforme TPS"
end end
def last_week_overview(gestionnaire, overview) def last_week_overview(gestionnaire)
headers['X-mailjet-campaign'] = 'last_week_overview' headers['X-mailjet-campaign'] = 'last_week_overview'
overview = gestionnaire.last_week_overview
send_mail gestionnaire.email, overview, 'Vos activités sur TPS' send_mail gestionnaire.email, overview, 'Vos activités sur TPS'
end end

View file

@ -4,7 +4,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do
describe 'perform' do describe 'perform' do
let!(:gestionnaire) { create(:gestionnaire) } let!(:gestionnaire) { create(:gestionnaire) }
let(:overview) { double('overview') } let(:overview) { double('overview') }
let(:mailer_double) { double('mailer', deliver_now: true) } let(:mailer_double) { double('mailer', deliver_later: true) }
context 'if the feature is enabled' do context 'if the feature is enabled' do
before { allow(Features).to receive(:weekly_overview).and_return(true) } before { allow(Features).to receive(:weekly_overview).and_return(true) }
@ -16,8 +16,8 @@ RSpec.describe WeeklyOverviewJob, type: :job do
WeeklyOverviewJob.new.perform WeeklyOverviewJob.new.perform
end end
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) } it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire) }
it { expect(mailer_double).to have_received(:deliver_now) } it { expect(mailer_double).to have_received(:deliver_later) }
end end
context 'with one gestionnaire with no overviews' do context 'with one gestionnaire with no overviews' do