diff --git a/app/jobs/admin_failed_gift_job.rb b/app/jobs/admin_failed_gift_job.rb index 499a1047..15f38693 100644 --- a/app/jobs/admin_failed_gift_job.rb +++ b/app/jobs/admin_failed_gift_job.rb @@ -1,7 +1,6 @@ -class AdminFailedGiftJob < ApplicationJob - queue_as :default +class AdminFailedGiftJob < EmailJob def perform(donation, campaign_gift_option) - AdminMailer.notify_failed_gift(donation, campaign_gift_option) + AdminMailer.notify_failed_gift(donation, campaign_gift_option).deliver_now end end diff --git a/app/jobs/bank_account_create_job.rb b/app/jobs/bank_account_create_job.rb index 95660788..f30c5c23 100644 --- a/app/jobs/bank_account_create_job.rb +++ b/app/jobs/bank_account_create_job.rb @@ -1,7 +1,6 @@ -class BankAccountCreateJob < ApplicationJob - queue_as :default +class BankAccountCreateJob < EmailJob def perform(bank_account) - NonprofitMailer.new_bank_account_notification(bank_account).deliver + NonprofitMailer.new_bank_account_notification(bank_account).deliver_now end end diff --git a/app/jobs/campaign_create_job.rb b/app/jobs/campaign_create_job.rb index d338bdce..3e6c41c3 100644 --- a/app/jobs/campaign_create_job.rb +++ b/app/jobs/campaign_create_job.rb @@ -3,9 +3,9 @@ class CampaignCreateJob < ApplicationJob def perform(campaign) if campaign.child_campaign? - CampaignMailer.federated_creation_followup(campaign).deliver_later + CampaignCreationFederatedEmailJob.perform_later(campaign) else - CampaignMailer.creation_followup(campaign).deliver_later + CampaignCreationEmailFollowupJob.perform_later(campaign) end SupporterFundraiserCreateJob.perform_later(campaign) diff --git a/app/jobs/campaign_creation_email_followup_job.rb b/app/jobs/campaign_creation_email_followup_job.rb index b87bdc2b..2ed45890 100644 --- a/app/jobs/campaign_creation_email_followup_job.rb +++ b/app/jobs/campaign_creation_email_followup_job.rb @@ -1,5 +1,4 @@ -class CampaignCreationEmailFollowupJob < ApplicationJob - queue_as :default +class CampaignCreationEmailFollowupJob < EmailJob def perform(campaign) CampaignMailer.creation_followup(campaign).deliver_now diff --git a/app/jobs/campaign_creation_federated_email_job.rb b/app/jobs/campaign_creation_federated_email_job.rb new file mode 100644 index 00000000..c80d8f90 --- /dev/null +++ b/app/jobs/campaign_creation_federated_email_job.rb @@ -0,0 +1,6 @@ +class CampaignCreationFederatedEmailJob < EmailJob + + def perform(campaign) + CampaignMailer.federated_creation_followup(campaign).deliver_now + end +end diff --git a/app/jobs/direct_debit_create_notify_donor_job.rb b/app/jobs/direct_debit_create_notify_donor_job.rb index 62bc3708..d720fc32 100644 --- a/app/jobs/direct_debit_create_notify_donor_job.rb +++ b/app/jobs/direct_debit_create_notify_donor_job.rb @@ -1,5 +1,4 @@ -class DirectDebitCreateNotifyDonorJob < ApplicationJob - queue_as :default +class DirectDebitCreateNotifyDonorJob < EmailJob def perform(donation_id, locale) DonationMailer.donor_direct_debit_notification(donation_id, locale).deliver_now diff --git a/app/jobs/direct_debit_create_notify_nonprofit_job.rb b/app/jobs/direct_debit_create_notify_nonprofit_job.rb index d7ec6056..d4771bd0 100644 --- a/app/jobs/direct_debit_create_notify_nonprofit_job.rb +++ b/app/jobs/direct_debit_create_notify_nonprofit_job.rb @@ -1,5 +1,4 @@ -class DirectDebitCreateNotifyNonprofitJob < ApplicationJob - queue_as :default +class DirectDebitCreateNotifyNonprofitJob < EmailJob def perform(*args) # Do something later diff --git a/app/jobs/email_job.rb b/app/jobs/email_job.rb new file mode 100644 index 00000000..e30bd65c --- /dev/null +++ b/app/jobs/email_job.rb @@ -0,0 +1,5 @@ +class EmailJob < ApplicationJob + queue_as :email_queue + + retry_on Exception, wait: ->(executions) { executions **2.195 }, attempts: MAX_EMAIL_JOB_ATTEMPTS || 1 +end diff --git a/app/jobs/event_create_creator_email_job.rb b/app/jobs/event_create_creator_email_job.rb index bb93e24b..391b936e 100644 --- a/app/jobs/event_create_creator_email_job.rb +++ b/app/jobs/event_create_creator_email_job.rb @@ -1,5 +1,4 @@ -class EventCreateCreatorEmailJob < ApplicationJob - queue_as :default +class EventCreateCreatorEmailJob < EmailJob def perform(event) EventMailer.creation_followup(event).deliver_now diff --git a/app/jobs/event_create_job.rb b/app/jobs/event_create_job.rb index e3f27edc..561a775a 100644 --- a/app/jobs/event_create_job.rb +++ b/app/jobs/event_create_job.rb @@ -2,6 +2,6 @@ class EventCreateJob < ApplicationJob queue_as :default def perform(event) - EventCreateCreatorEmailJob(event) + EventCreateCreatorEmailJob.perform_later(event) end end diff --git a/app/jobs/export_payments_completed_job.rb b/app/jobs/export_payments_completed_job.rb index 0de11cf1..49619415 100644 --- a/app/jobs/export_payments_completed_job.rb +++ b/app/jobs/export_payments_completed_job.rb @@ -1,5 +1,4 @@ -class ExportPaymentsCompletedJob < ApplicationJob - queue_as :default +class ExportPaymentsCompletedJob < EmailJob def perform(export) ExportMailer.export_payments_completed_notification(export).deliver_now diff --git a/app/jobs/export_payments_failed_job.rb b/app/jobs/export_payments_failed_job.rb index d8be1f6a..8acbcb2a 100644 --- a/app/jobs/export_payments_failed_job.rb +++ b/app/jobs/export_payments_failed_job.rb @@ -1,5 +1,4 @@ -class ExportPaymentsFailedJob < ApplicationJob - queue_as :default +class ExportPaymentsFailedJob < EmailJob def perform(export) ExportMailer.export_payments_failed_notification(export).deliver_now diff --git a/app/jobs/export_recurring_donations_completed_job.rb b/app/jobs/export_recurring_donations_completed_job.rb index e39c22dd..245dfdda 100644 --- a/app/jobs/export_recurring_donations_completed_job.rb +++ b/app/jobs/export_recurring_donations_completed_job.rb @@ -1,5 +1,4 @@ -class ExportRecurringDonationsCompletedJob < ApplicationJob - queue_as :default +class ExportRecurringDonationsCompletedJob < EmailJob def perform(export) ExportMailer.export_recurring_donations_completed_notification(@export).deliver_now diff --git a/app/jobs/export_recurring_donations_failed_job.rb b/app/jobs/export_recurring_donations_failed_job.rb index 37738745..b1dd904e 100644 --- a/app/jobs/export_recurring_donations_failed_job.rb +++ b/app/jobs/export_recurring_donations_failed_job.rb @@ -1,5 +1,4 @@ -class ExportRecurringDonationsFailedJob < ApplicationJob - queue_as :default +class ExportRecurringDonationsFailedJob < EmailJob def perform(export) ExportMailer.export_recurring_donations_failed_notification(export).deliver_now diff --git a/app/jobs/export_supporter_notes_completed_job.rb b/app/jobs/export_supporter_notes_completed_job.rb index 3aa17c00..bfcf9993 100644 --- a/app/jobs/export_supporter_notes_completed_job.rb +++ b/app/jobs/export_supporter_notes_completed_job.rb @@ -1,5 +1,4 @@ -class ExportSupporterNotesCompletedJob < ApplicationJob - queue_as :default +class ExportSupporterNotesCompletedJob < EmailJob def perform(export) ExportMailer.export_supporter_notes_completed_notification(export).deliver_now diff --git a/app/jobs/export_supporter_notes_failed_job.rb b/app/jobs/export_supporter_notes_failed_job.rb index d43fae66..ba59a7ba 100644 --- a/app/jobs/export_supporter_notes_failed_job.rb +++ b/app/jobs/export_supporter_notes_failed_job.rb @@ -1,5 +1,4 @@ -class ExportSupporterNotesFailedJob < ApplicationJob - queue_as :default +class ExportSupporterNotesFailedJob < EmailJob def perform(export) ExportMailer.export_supporter_notes_failed_notification(export).deliver_now diff --git a/app/jobs/export_supporters_completed_job.rb b/app/jobs/export_supporters_completed_job.rb index b2c1a19d..0d06045f 100644 --- a/app/jobs/export_supporters_completed_job.rb +++ b/app/jobs/export_supporters_completed_job.rb @@ -1,5 +1,4 @@ -class ExportSupportersCompletedJob < ApplicationJob - queue_as :default +class ExportSupportersCompletedJob < EmailJob def perform(export) ExportMailer.export_supporters_completed_notification(export).deliver_now diff --git a/app/jobs/export_supporters_failed_job.rb b/app/jobs/export_supporters_failed_job.rb index 3f1a62d9..4da0f375 100644 --- a/app/jobs/export_supporters_failed_job.rb +++ b/app/jobs/export_supporters_failed_job.rb @@ -1,5 +1,4 @@ -class ExportSupportersFailedJob < ApplicationJob - queue_as :default +class ExportSupportersFailedJob < EmailJob def perform(export) ExportMailer.export_supporters_failed_notification(export).deliver_now diff --git a/app/jobs/failed_recurring_donation_payment_donor_email_job.rb b/app/jobs/failed_recurring_donation_payment_donor_email_job.rb index 43a812c3..90054cd4 100644 --- a/app/jobs/failed_recurring_donation_payment_donor_email_job.rb +++ b/app/jobs/failed_recurring_donation_payment_donor_email_job.rb @@ -1,5 +1,4 @@ -class FailedRecurringDonationPaymentDonorEmailJob < ApplicationJob - queue_as :default +class FailedRecurringDonationPaymentDonorEmailJob < EmailJob def perform(donation) DonationMailer.donor_failed_recurring_donation(donation.id).deliver_now diff --git a/app/jobs/failed_recurring_donation_payment_nonprofit_email_job.rb b/app/jobs/failed_recurring_donation_payment_nonprofit_email_job.rb index 74022571..c9ed53a7 100644 --- a/app/jobs/failed_recurring_donation_payment_nonprofit_email_job.rb +++ b/app/jobs/failed_recurring_donation_payment_nonprofit_email_job.rb @@ -1,5 +1,4 @@ -class FailedRecurringDonationPaymentNonprofitEmailJob < ApplicationJob - queue_as :default +class FailedRecurringDonationPaymentNonprofitEmailJob < EmailJob def perform(donation) DonationMailer.nonprofit_failed_recurring_donation(donation.id).deliver_now diff --git a/app/jobs/import_completed_job.rb b/app/jobs/import_completed_job.rb index b8a96102..82fb6336 100644 --- a/app/jobs/import_completed_job.rb +++ b/app/jobs/import_completed_job.rb @@ -1,5 +1,4 @@ -class ImportCompletedJob < ApplicationJob - queue_as :default +class ImportCompletedJob < EmailJob def perform(import) ImportMailer.import_completed_notification(import.id).deliver_now diff --git a/app/jobs/nonprofit_create_job.rb b/app/jobs/nonprofit_create_job.rb index 98ee7a11..10a3c2e2 100644 --- a/app/jobs/nonprofit_create_job.rb +++ b/app/jobs/nonprofit_create_job.rb @@ -1,7 +1,6 @@ -class NonprofitCreateJob < ApplicationJob - queue_as :default +class NonprofitCreateJob < EmailJob def perform(nonprofit) - NonprofitMailer.welcome(nonprofit.id).deliver + NonprofitMailer.welcome(nonprofit.id).deliver_now end end diff --git a/app/jobs/payment_notification_email_donor_job.rb b/app/jobs/payment_notification_email_donor_job.rb index f4cca0b9..5c49b97b 100644 --- a/app/jobs/payment_notification_email_donor_job.rb +++ b/app/jobs/payment_notification_email_donor_job.rb @@ -1,5 +1,4 @@ -class PaymentNotificationEmailDonorJob < ApplicationJob - queue_as :default +class PaymentNotificationEmailDonorJob < EmailJob def perform(donation, locale) DonationMailer.donor_payment_notification(donation.id, locale).deliver_now diff --git a/app/jobs/payment_notification_email_nonprofit_job.rb b/app/jobs/payment_notification_email_nonprofit_job.rb index 30d99c72..0b246b02 100644 --- a/app/jobs/payment_notification_email_nonprofit_job.rb +++ b/app/jobs/payment_notification_email_nonprofit_job.rb @@ -1,5 +1,4 @@ -class PaymentNotificationEmailNonprofitJob < ApplicationJob - queue_as :default +class PaymentNotificationEmailNonprofitJob < EmailJob def perform(donation, user=nil) DonationMailer.nonprofit_payment_notification(donation.id, user&.id).deliver_now diff --git a/app/jobs/payout_pending_job.rb b/app/jobs/payout_pending_job.rb index 250c7324..240cfe7d 100644 --- a/app/jobs/payout_pending_job.rb +++ b/app/jobs/payout_pending_job.rb @@ -1,5 +1,4 @@ -class PayoutPendingJob < ApplicationJob - queue_as :default +class PayoutPendingJob < EmailJob def perform(payout) NonprofitMailer.pending_payout_notification(payout.id).deliver_now diff --git a/app/jobs/recurring_donation_cancelled_job.rb b/app/jobs/recurring_donation_cancelled_job.rb index da159a3c..e23699c2 100644 --- a/app/jobs/recurring_donation_cancelled_job.rb +++ b/app/jobs/recurring_donation_cancelled_job.rb @@ -1,7 +1,6 @@ -class RecurringDonationCancelledJob < ApplicationJob - queue_as :default +class RecurringDonationCancelledJob < EmailJob def perform(donation) - DonationMailer.nonprofit_recurring_donation_cancellation(donation.id).deliver_later + DonationMailer.nonprofit_recurring_donation_cancellation(donation.id).deliver_now end end diff --git a/app/jobs/recurring_donation_change_amount_donor_email_job.rb b/app/jobs/recurring_donation_change_amount_donor_email_job.rb index c97615ad..24aada63 100644 --- a/app/jobs/recurring_donation_change_amount_donor_email_job.rb +++ b/app/jobs/recurring_donation_change_amount_donor_email_job.rb @@ -1,5 +1,4 @@ -class RecurringDonationChangeAmountDonorEmailJob < ApplicationJob - queue_as :default +class RecurringDonationChangeAmountDonorEmailJob < EmailJob def perform(recurring_donation, previous_amount) DonationMailer.donor_recurring_donation_change_amount(recurring_donation.id, previous_amount).deliver_now diff --git a/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb b/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb index 27f2fb56..9039cb9d 100644 --- a/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb +++ b/app/jobs/recurring_donation_change_amount_nonprofit_email_job.rb @@ -1,5 +1,4 @@ -class RecurringDonationChangeAmountNonprofitEmailJob < ApplicationJob - queue_as :default +class RecurringDonationChangeAmountNonprofitEmailJob < EmailJob def perform(recurring_donation, previous_amount) DonationMailer.nonprofit_recurring_donation_change_amount(recurring_donation.id, previous_amount).deliver_now diff --git a/app/jobs/refund_notification_donor_email_job.rb b/app/jobs/refund_notification_donor_email_job.rb index 6a9d70c3..946eb462 100644 --- a/app/jobs/refund_notification_donor_email_job.rb +++ b/app/jobs/refund_notification_donor_email_job.rb @@ -1,5 +1,4 @@ -class RefundNotificationDonorEmailJob < ApplicationJob - queue_as :default +class RefundNotificationDonorEmailJob < EmailJob def perform(refund) UserMailer.refund_receipt(refund).deliver_now diff --git a/app/jobs/refund_notification_job.rb b/app/jobs/refund_notification_job.rb index c29b6c52..0c7632d0 100644 --- a/app/jobs/refund_notification_job.rb +++ b/app/jobs/refund_notification_job.rb @@ -1,5 +1,4 @@ -class RefundNotificationJob < ApplicationJob - queue_as :default +class RefundNotificationJob < EmailJob def perform(refund) RefundNotificationDonorEmailJob.perform_later(refund) diff --git a/app/jobs/refund_notification_nonprofit_email_job.rb b/app/jobs/refund_notification_nonprofit_email_job.rb index 26c970a6..bef576f1 100644 --- a/app/jobs/refund_notification_nonprofit_email_job.rb +++ b/app/jobs/refund_notification_nonprofit_email_job.rb @@ -1,5 +1,4 @@ -class RefundNotificationNonprofitEmailJob < ApplicationJob - queue_as :default +class RefundNotificationNonprofitEmailJob < EmailJob def perform(refund) NonprofitMailer.refund_notification(refund.id).deliver_now diff --git a/app/jobs/role_added_job.rb b/app/jobs/role_added_job.rb index fc9b0401..1706e35a 100644 --- a/app/jobs/role_added_job.rb +++ b/app/jobs/role_added_job.rb @@ -1,5 +1,4 @@ -class RoleAddedJob < ApplicationJob - queue_as :default +class RoleAddedJob < EmailJob def perform(role) NonprofitAdminMailer.existing_invite(role).deliver_now diff --git a/app/jobs/stripe_account_create_job.rb b/app/jobs/stripe_account_create_job.rb index 97ead65e..a1e82be8 100644 --- a/app/jobs/stripe_account_create_job.rb +++ b/app/jobs/stripe_account_create_job.rb @@ -1,5 +1,4 @@ -class StripeAccountCreateJob < ApplicationJob - queue_as :default +class StripeAccountCreateJob < EmailJob def perform(nonprofit) NonprofitMailer.setup_verification(nonprofit.id).deliver_now diff --git a/app/jobs/supporter_notes_export_create_job.rb b/app/jobs/supporter_notes_export_create_job.rb index 9cebcfd6..c4594955 100644 --- a/app/jobs/supporter_notes_export_create_job.rb +++ b/app/jobs/supporter_notes_export_create_job.rb @@ -1,4 +1,4 @@ -class SupporterNotesExportCreateJob < ApplicationJob +class SupporterNotesExportCreateJob < EmailJob queue_as :default def perform(npo_id, params, user_id, export_id) diff --git a/app/jobs/supporters_export_create_job.rb b/app/jobs/supporters_export_create_job.rb index 5c06c373..8ad1f1d5 100644 --- a/app/jobs/supporters_export_create_job.rb +++ b/app/jobs/supporters_export_create_job.rb @@ -1,5 +1,4 @@ -class SupportersExportCreateJob < ApplicationJob - queue_as :default +class SupportersExportCreateJob < EmailJob def perform(*args) ExportSupporters.run_export(*args) diff --git a/app/jobs/user_invite_create_job.rb b/app/jobs/user_invite_create_job.rb index 13b73e32..243c4e62 100644 --- a/app/jobs/user_invite_create_job.rb +++ b/app/jobs/user_invite_create_job.rb @@ -1,5 +1,4 @@ -class UserInviteCreateJob < ApplicationJob - queue_as :default +class UserInviteCreateJob < EmailJob def perform(role, raw_token) NonprofitAdminMailer.new_invite(role, raw_token).deliver_now diff --git a/app/jobs/verification_completed_job.rb b/app/jobs/verification_completed_job.rb index 9eb9eac7..7e939161 100644 --- a/app/jobs/verification_completed_job.rb +++ b/app/jobs/verification_completed_job.rb @@ -1,5 +1,4 @@ -class VerificationCompletedJob < ApplicationJob - queue_as :default +class VerificationCompletedJob < EmailJob def perform(nonprofit) NonprofitMailer.successful_verification_notice(nonprofit).deliver_now diff --git a/app/jobs/verification_failed_job.rb b/app/jobs/verification_failed_job.rb index 05217238..708af204 100644 --- a/app/jobs/verification_failed_job.rb +++ b/app/jobs/verification_failed_job.rb @@ -1,5 +1,4 @@ -class VerificationFailedJob < ApplicationJob - queue_as :default +class VerificationFailedJob < EmailJob def perform(nonprofit) NonprofitMailer.failed_verification_notice(onprofit).deliver_now diff --git a/lib/job_types/email_job.rb b/lib/job_types/email_job.rb deleted file mode 100644 index d238ca29..00000000 --- a/lib/job_types/email_job.rb +++ /dev/null @@ -1,28 +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 EmailJob - def perform - raise 'You need to override this' - end - - def max_attempts - MAX_EMAIL_JOB_ATTEMPTS || 1 - end - - def destroy_failed_jobs? - false - end - - def error(job, exception); end - - def reschedule_at(current_time, attempts) - current_time + attempts**2.195 - end - - def queue_name - 'email_queue' - end - end -end diff --git a/spec/lib/insert/insert_source_token_spec.rb b/spec/lib/insert/insert_source_token_spec.rb index 375e39c6..b7a5034b 100644 --- a/spec/lib/insert/insert_source_token_spec.rb +++ b/spec/lib/insert/insert_source_token_spec.rb @@ -61,14 +61,12 @@ describe InsertSourceToken do ouruuid = nil tokenizable = Card.create! - expect(SecureRandom).to receive(:uuid).and_wrap_original { |m| ouruuid = m.call; ouruuid } result = InsertSourceToken.create_record(tokenizable, event: event) expected = { tokenizable_id: tokenizable.id, tokenizable_type: 'Card', - token: ouruuid, expiration: Time.now + 1.day + 20.days, created_at: Time.now, updated_at: Time.now, @@ -77,9 +75,11 @@ describe InsertSourceToken do event_id: event.id }.with_indifferent_access - expect(result.attributes).to eq expected + expect(result.attributes.except('token')).to eq expected - expect(SourceToken.last.attributes).to eq expected + expect(SourceToken.last.attributes.except('token')).to eq expected + + expect(result[:token]).to be_a String end end end @@ -89,13 +89,11 @@ describe InsertSourceToken do ouruuid = nil tokenizable = Card.create! - expect(SecureRandom).to receive(:uuid).and_wrap_original { |m| ouruuid = m.call; ouruuid } result = InsertSourceToken.create_record(tokenizable, max_uses: 50, expiration_time: 3600) expected = { tokenizable_id: tokenizable.id, tokenizable_type: 'Card', - token: ouruuid, expiration: Time.now.since(1.hour), created_at: Time.now, updated_at: Time.now, @@ -103,8 +101,11 @@ describe InsertSourceToken do max_uses: 50, event_id: nil }.with_indifferent_access - expect(result.attributes.with_indifferent_access).to eq expected - expect(SourceToken.last.attributes).to eq expected + expect(result.attributes.with_indifferent_access.except(:token)).to eq expected + + + expect(SourceToken.last.attributes.except('token')).to eq expected + expect(result.token).to be_a String end end @@ -113,14 +114,12 @@ describe InsertSourceToken do ouruuid = nil tokenizable = Card.create! - expect(SecureRandom).to receive(:uuid).and_wrap_original { |m| ouruuid = m.call; ouruuid } result = InsertSourceToken.create_record(tokenizable, max_uses: 50, expiration_time: 3600, event: event) expected = { tokenizable_id: tokenizable.id, tokenizable_type: 'Card', - token: ouruuid, expiration: Time.now.since(1.day).since(1.hour), created_at: Time.now, updated_at: Time.now, @@ -129,8 +128,9 @@ describe InsertSourceToken do event_id: event.id }.with_indifferent_access - expect(result.attributes.with_indifferent_access).to eq expected - expect(SourceToken.last.attributes).to eq expected + expect(result.attributes.with_indifferent_access.except(:token)).to eq expected + expect(SourceToken.last.attributes.except('token')).to eq expected + expect(result.token).to be_a String end end end