Add EmailJob

This commit is contained in:
Eric Schultz 2019-11-08 15:32:33 -06:00
parent d544242ae7
commit c2226c9893
40 changed files with 64 additions and 114 deletions

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -1,5 +1,4 @@
class CampaignCreationEmailFollowupJob < ApplicationJob
queue_as :default
class CampaignCreationEmailFollowupJob < EmailJob
def perform(campaign)
CampaignMailer.creation_followup(campaign).deliver_now

View file

@ -0,0 +1,6 @@
class CampaignCreationFederatedEmailJob < EmailJob
def perform(campaign)
CampaignMailer.federated_creation_followup(campaign).deliver_now
end
end

View file

@ -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

View file

@ -1,5 +1,4 @@
class DirectDebitCreateNotifyNonprofitJob < ApplicationJob
queue_as :default
class DirectDebitCreateNotifyNonprofitJob < EmailJob
def perform(*args)
# Do something later

5
app/jobs/email_job.rb Normal file
View file

@ -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

View file

@ -1,5 +1,4 @@
class EventCreateCreatorEmailJob < ApplicationJob
queue_as :default
class EventCreateCreatorEmailJob < EmailJob
def perform(event)
EventMailer.creation_followup(event).deliver_now

View file

@ -2,6 +2,6 @@ class EventCreateJob < ApplicationJob
queue_as :default
def perform(event)
EventCreateCreatorEmailJob(event)
EventCreateCreatorEmailJob.perform_later(event)
end
end

View file

@ -1,5 +1,4 @@
class ExportPaymentsCompletedJob < ApplicationJob
queue_as :default
class ExportPaymentsCompletedJob < EmailJob
def perform(export)
ExportMailer.export_payments_completed_notification(export).deliver_now

View file

@ -1,5 +1,4 @@
class ExportPaymentsFailedJob < ApplicationJob
queue_as :default
class ExportPaymentsFailedJob < EmailJob
def perform(export)
ExportMailer.export_payments_failed_notification(export).deliver_now

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,4 @@
class ExportSupportersCompletedJob < ApplicationJob
queue_as :default
class ExportSupportersCompletedJob < EmailJob
def perform(export)
ExportMailer.export_supporters_completed_notification(export).deliver_now

View file

@ -1,5 +1,4 @@
class ExportSupportersFailedJob < ApplicationJob
queue_as :default
class ExportSupportersFailedJob < EmailJob
def perform(export)
ExportMailer.export_supporters_failed_notification(export).deliver_now

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,4 @@
class ImportCompletedJob < ApplicationJob
queue_as :default
class ImportCompletedJob < EmailJob
def perform(import)
ImportMailer.import_completed_notification(import.id).deliver_now

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,4 @@
class PayoutPendingJob < ApplicationJob
queue_as :default
class PayoutPendingJob < EmailJob
def perform(payout)
NonprofitMailer.pending_payout_notification(payout.id).deliver_now

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,4 @@
class RefundNotificationDonorEmailJob < ApplicationJob
queue_as :default
class RefundNotificationDonorEmailJob < EmailJob
def perform(refund)
UserMailer.refund_receipt(refund).deliver_now

View file

@ -1,5 +1,4 @@
class RefundNotificationJob < ApplicationJob
queue_as :default
class RefundNotificationJob < EmailJob
def perform(refund)
RefundNotificationDonorEmailJob.perform_later(refund)

View file

@ -1,5 +1,4 @@
class RefundNotificationNonprofitEmailJob < ApplicationJob
queue_as :default
class RefundNotificationNonprofitEmailJob < EmailJob
def perform(refund)
NonprofitMailer.refund_notification(refund.id).deliver_now

View file

@ -1,5 +1,4 @@
class RoleAddedJob < ApplicationJob
queue_as :default
class RoleAddedJob < EmailJob
def perform(role)
NonprofitAdminMailer.existing_invite(role).deliver_now

View file

@ -1,5 +1,4 @@
class StripeAccountCreateJob < ApplicationJob
queue_as :default
class StripeAccountCreateJob < EmailJob
def perform(nonprofit)
NonprofitMailer.setup_verification(nonprofit.id).deliver_now

View file

@ -1,4 +1,4 @@
class SupporterNotesExportCreateJob < ApplicationJob
class SupporterNotesExportCreateJob < EmailJob
queue_as :default
def perform(npo_id, params, user_id, export_id)

View file

@ -1,5 +1,4 @@
class SupportersExportCreateJob < ApplicationJob
queue_as :default
class SupportersExportCreateJob < EmailJob
def perform(*args)
ExportSupporters.run_export(*args)

View file

@ -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

View file

@ -1,5 +1,4 @@
class VerificationCompletedJob < ApplicationJob
queue_as :default
class VerificationCompletedJob < EmailJob
def perform(nonprofit)
NonprofitMailer.successful_verification_notice(nonprofit).deliver_now

View file

@ -1,5 +1,4 @@
class VerificationFailedJob < ApplicationJob
queue_as :default
class VerificationFailedJob < EmailJob
def perform(nonprofit)
NonprofitMailer.failed_verification_notice(onprofit).deliver_now

View file

@ -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

View file

@ -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