From ce46863e76583a4eac8f4ee22f192713ee6880fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Friebel?= Date: Fri, 2 Oct 2020 11:53:27 +0200 Subject: [PATCH] execute workflows in order of their positioning --- app/models/custom_workflow.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 1ee2318..82facb2 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -36,6 +36,7 @@ class CustomWorkflow < ActiveRecord::Base validate :validate_syntax, :validate_scripts_presence, if: Proc.new { |workflow| workflow.respond_to?(:observable) and workflow.active? } scope :active, lambda { where(active: true) } + scope :sorted, lambda { order(:position) } scope :for_project, (lambda do |project| where("is_for_all=? OR EXISTS (SELECT * FROM #{reflect_on_association(:projects).join_table} WHERE project_id=? AND custom_workflow_id=id)", true, project.id) @@ -57,7 +58,7 @@ def self.log_message(str, object) def self.run_shared_code(object) log_message '= Running shared code', object if CustomWorkflow.table_exists? # Due to DB migration - CustomWorkflow.active.where(observable: :shared).find_each do |workflow| + CustomWorkflow.active.where(observable: :shared).sorted.each do |workflow| unless workflow.run(object, :shared_code) log_message '= Abort running shared code', object return false @@ -77,7 +78,7 @@ def self.run_custom_workflows(observable, object, event) end return true unless workflows.any? log_message "= Running #{event} custom workflows", object - workflows.each do |workflow| + workflows.sorted.each do |workflow| unless workflow.run(object, event) log_message "= Abort running #{event} custom workflows", object return false