diff --git a/app/jobs/table_simulator_job.rb b/app/jobs/table_simulator_job.rb index ef91719..ced9b2d 100644 --- a/app/jobs/table_simulator_job.rb +++ b/app/jobs/table_simulator_job.rb @@ -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 diff --git a/app/models/guest.rb b/app/models/guest.rb index 8983c66..929cc6e 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 206f7da..e493f6b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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)) }