Adapt background job to use acts as tenant
This commit is contained in:
parent
8429b3952b
commit
4d9563cab7
@ -3,21 +3,23 @@
|
||||
class TableSimulatorJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(*_args)
|
||||
engine = VNS::Engine.new
|
||||
def perform(wedding_id)
|
||||
ActsAsTenant.with_tenant(Wedding.find(wedding_id)) do
|
||||
engine = VNS::Engine.new
|
||||
|
||||
engine.add_perturbation(Tables::Swap)
|
||||
engine.add_perturbation(Tables::Shift)
|
||||
engine.add_perturbation(Tables::Swap)
|
||||
engine.add_perturbation(Tables::Shift)
|
||||
|
||||
initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10)
|
||||
initial_solution.random_distribution(Guest.potential.shuffle)
|
||||
initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10)
|
||||
initial_solution.random_distribution(Guest.potential.shuffle)
|
||||
|
||||
engine.initial_solution = initial_solution
|
||||
engine.initial_solution = initial_solution
|
||||
|
||||
engine.target_function(&:discomfort)
|
||||
engine.target_function(&:discomfort)
|
||||
|
||||
best_solution = engine.run
|
||||
best_solution = engine.run
|
||||
|
||||
best_solution.save!
|
||||
best_solution.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -49,6 +49,6 @@ class Guest < ApplicationRecord
|
||||
def recalculate_simulations
|
||||
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
|
||||
|
@ -8,8 +8,9 @@ Guest.delete_all
|
||||
Group.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: 'Country house', amount: 6000, pricing_type: 'fixed')
|
||||
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
|
||||
|
||||
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)) }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user