Implement Run all rules (#582)

This commit is contained in:
soky srm
2026-01-08 15:20:14 +01:00
committed by GitHub
parent c315e08a6e
commit e37c03d1d4
11 changed files with 239 additions and 0 deletions

33
lib/tasks/rules.rake Normal file
View File

@@ -0,0 +1,33 @@
namespace :rules do
desc "Apply all rules for a family"
task :apply_all, [ :family_id ] => :environment do |_t, args|
family_id = args[:family_id]
if family_id.blank?
puts "Usage: bin/rails rules:apply_all[family_id]"
exit 1
end
family = Family.find(family_id)
rules = family.rules
if rules.empty?
puts "No rules found for family #{family_id}"
exit 0
end
puts "Applying #{rules.count} rules for family #{family_id}..."
rules.find_each do |rule|
print " Applying rule '#{rule.name || rule.id}'... "
begin
RuleJob.perform_now(rule, ignore_attribute_locks: true, execution_type: "manual")
puts "done"
rescue => e
puts "failed: #{e.message}"
end
end
puts "Finished applying all rules"
end
end