Adapt background job to use acts as tenant

This commit is contained in:
Manuel Bustillo 2024-12-01 10:41:05 +01:00
parent 8429b3952b
commit 4d9563cab7
3 changed files with 16 additions and 13 deletions

View File

@ -3,7 +3,8 @@
class TableSimulatorJob < ApplicationJob class TableSimulatorJob < ApplicationJob
queue_as :default queue_as :default
def perform(*_args) def perform(wedding_id)
ActsAsTenant.with_tenant(Wedding.find(wedding_id)) do
engine = VNS::Engine.new engine = VNS::Engine.new
engine.add_perturbation(Tables::Swap) engine.add_perturbation(Tables::Swap)
@ -21,3 +22,4 @@ class TableSimulatorJob < ApplicationJob
best_solution.save! best_solution.save!
end end
end end
end

View File

@ -49,6 +49,6 @@ class Guest < ApplicationRecord
def recalculate_simulations def recalculate_simulations
TablesArrangement.delete_all TablesArrangement.delete_all
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new }) ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new(wedding_id) })
end end
end end

View File

@ -8,8 +8,9 @@ Guest.delete_all
Group.delete_all Group.delete_all
Wedding.delete_all Wedding.delete_all
wedding = Wedding.create!(slug: :default, date: 1.year.from_now)
ActsAsTenant.with_tenant(Wedding.create!(slug: :default, date: 1.year.from_now)) do ActsAsTenant.with_tenant(wedding) do
Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed') Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed') Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed')
Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person') Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person')
@ -66,7 +67,7 @@ ActsAsTenant.with_tenant(Wedding.create!(slug: :default, date: 1.year.from_now))
) )
end end
ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new }) ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new(wedding.id) })
'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) } 'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }