Skip to content

A platform for community discussion. Free, open, simple.

FIX: Trigger error workflows when waits time out (#43723)

Régis Hanol231b4c993799
diff --git a/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb b/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb
index 0db30c4dc93..881adb06e6d 100644
--- a/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb
+++ b/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb
@@ -201,6 +201,7 @@ module DiscourseWorkflows
if claimed
reload
+ trigger_error_workflow(StandardError.new(message))
DiscourseWorkflows::ExecutionProgressPublisher.publish(self, refresh: true)
DiscourseWorkflows::WorkflowCallContinuation.child_failed!(self)
end
@@ -208,6 +209,15 @@ module DiscourseWorkflows
claimed
end
+ def trigger_error_workflow(error, steps: execution_data&.steps_array || [])
+ Executor::ErrorWorkflowTrigger.new(
+ workflow,
+ steps,
+ execution: self,
+ execution_mode: execution_mode.to_sym,
+ ).trigger_error_workflow(error)
+ end
+
def waiting_step_input_items
return [{ "json" => {} }] unless execution_data
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb b/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb
index 3446e5ac313..22c95d26a58 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb
@@ -80,7 +80,7 @@ module DiscourseWorkflows
waiting_until: nil,
timeout_action: nil,
)
- trigger_error_workflow(error, steps)
+ execution.trigger_error_workflow(error, steps: steps)
publish_execution_run_data(
force: @options.draft_execution || @options.workflow_snapshot.present?,
)
@@ -481,15 +481,6 @@ module DiscourseWorkflows
Array(ports).map { |port| port.except("items").merge("items" => [], "truncated" => true) }
end
- def trigger_error_workflow(error, steps)
- ErrorWorkflowTrigger.new(
- workflow,
- steps,
- execution: execution,
- execution_mode: @options.execution_mode,
- ).trigger_error_workflow(error)
- end
-
def publish_waiting_form_notification(node)
return unless node.type == "action:form"
return if @workflow_snapshot.nil?
diff --git a/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb b/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb
index 35678f439fb..cd5eb0251a9 100644
--- a/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb
+++ b/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb
@@ -140,6 +140,26 @@ RSpec.describe DiscourseWorkflows::Execution do
waiting_until: eq_time(next_wait[:waiting_until]),
)
end
+
+ it "enqueues the configured error workflow when a wait times out" do
+ error_graph =
+ build_workflow_graph { |workflow_graph| workflow_graph.node "error-1", "trigger:error" }
+ error_workflow = Fabricate(:discourse_workflows_workflow, published: true, **error_graph)
+ workflow.update!(error_workflow_id: error_workflow.id)
+
+ expect(execution.fail_with_timeout!).to eq(true)
+
+ expect(
+ Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.map { |job| job["args"].first },
+ ).to contain_exactly(
+ include(
+ "workflow_id" => error_workflow.id,
+ "trigger_node_id" => "error-1",
+ "execution_mode" => "error_mode",
+ "trigger_data" => include("execution" => include("id" => execution.id.to_s)),
+ ),
+ )
+ end
end
describe ".compute_run_time_ms" do