Class: Munificent::DonatorBundleAssignmentJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/munificent/donator_bundle_assignment_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(donator_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/jobs/munificent/donator_bundle_assignment_job.rb', line 5

def perform(donator_id)
  if (donator = Donator.find_by(id: donator_id)).blank?
    Rollbar.error("Donator not found", donator_id:)
    return
  end

  Fundraiser.active.open.each do |fundraiser|
    next if (total_donations = donator.total_donations(fundraiser:)).zero?

    fundraiser.bundles.each do |bundle|
      DonatorBundleAssigner.assign(donator:, bundle:, fund: total_donations) if bundle.live?
    end
  end
end