From 94398f8bdf505ca55daa34db6cc87ee772c678f6 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 7 Nov 2019 13:00:10 -0600 Subject: [PATCH] Add PayoutPendingJob --- app/jobs/payout_pending_job.rb | 7 +++++++ lib/insert/insert_payout.rb | 2 +- lib/job_types/nonprofit_pending_payout_job.rb | 16 ---------------- lib/update/update_payouts.rb | 1 - .../nonprofit_pending_payout_job_spec.rb | 15 --------------- 5 files changed, 8 insertions(+), 33 deletions(-) create mode 100644 app/jobs/payout_pending_job.rb delete mode 100644 lib/job_types/nonprofit_pending_payout_job.rb delete mode 100644 spec/lib/job_types/nonprofit_pending_payout_job_spec.rb diff --git a/app/jobs/payout_pending_job.rb b/app/jobs/payout_pending_job.rb new file mode 100644 index 00000000..250c7324 --- /dev/null +++ b/app/jobs/payout_pending_job.rb @@ -0,0 +1,7 @@ +class PayoutPendingJob < ApplicationJob + queue_as :default + + def perform(payout) + NonprofitMailer.pending_payout_notification(payout.id).deliver_now + end +end diff --git a/lib/insert/insert_payout.rb b/lib/insert/insert_payout.rb index b8a52fd2..e9acb808 100644 --- a/lib/insert/insert_payout.rb +++ b/lib/insert/insert_payout.rb @@ -69,7 +69,7 @@ module InsertPayout ).first # Create PaymentPayout records linking all the payments to the payout pps = Psql.execute(Qexpr.new.insert('payment_payouts', payment_ids.map { |id| { payment_id: id.to_i } }, common_data: { payout_id: payout['id'].to_i })) - NonprofitMailer.delay.pending_payout_notification(payout['id'].to_i) + PayoutPendingJob.perform_later(Payout.find(payout['id'].to_i)) return payout end rescue Stripe::StripeError => e diff --git a/lib/job_types/nonprofit_pending_payout_job.rb b/lib/job_types/nonprofit_pending_payout_job.rb deleted file mode 100644 index 827db759..00000000 --- a/lib/job_types/nonprofit_pending_payout_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -module JobTypes - class NonprofitPendingPayoutJob < EmailJob - attr_reader :payout_id - - def initialize(payout_id) - @payout_id = payout_id - end - - def perform - NonprofitMailer.pending_payout_notification(@payout_id).deliver - end - end -end diff --git a/lib/update/update_payouts.rb b/lib/update/update_payouts.rb index 257523f7..fc4d63b5 100644 --- a/lib/update/update_payouts.rb +++ b/lib/update/update_payouts.rb @@ -34,7 +34,6 @@ module UpdatePayouts payout.failure_message = failure_message payout.save! - # NonprofitMailer.delay.pending_payout_notification(payout['id'].to_i) payout end end diff --git a/spec/lib/job_types/nonprofit_pending_payout_job_spec.rb b/spec/lib/job_types/nonprofit_pending_payout_job_spec.rb deleted file mode 100644 index a4d2cdd0..00000000 --- a/spec/lib/job_types/nonprofit_pending_payout_job_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -require 'rails_helper.rb' - -describe JobTypes::NonprofitPendingPayoutJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(NonprofitMailer).to receive(:pending_payout_notification).with(1).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::NonprofitPendingPayoutJob.new(1) - job.perform - end - end -end