Skip to content

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

FIX: Show steps that already ran when opening a running workflow execution

Régis Hanol21cd4e896e30
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs
index 5f65cfe6cf2..796e8a252ac 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs
@@ -221,6 +221,10 @@ function hasNoOutput(step) {
);
}
+function hasStepData(step) {
+ return step.input !== undefined;
+}
+
function isFilterStep(step) {
return step.node_type === "condition:filter";
}
@@ -819,30 +823,32 @@ export default class ExecutionDetail extends Component {
</div>
{{/if}}
- <details class="workflows-execution-detail__step-section">
- <summary>
- {{i18n "discourse_workflows.executions.input"}}
- {{#if (itemCount step.input)}}
- <span
- class="workflows-execution-detail__item-count"
- >{{itemCount step.input}}
- {{i18n "discourse_workflows.executions.items"}}</span>
- {{/if}}
- </summary>
- <pre>{{formatInputData step.input}}</pre>
- </details>
- <details class="workflows-execution-detail__step-section">
- <summary>
- {{i18n "discourse_workflows.executions.output"}}
- {{#if (itemCount step.output)}}
- <span
- class="workflows-execution-detail__item-count"
- >{{itemCount step.output}}
- {{i18n "discourse_workflows.executions.items"}}</span>
- {{/if}}
- </summary>
- <pre>{{formatOutputData step.output}}</pre>
- </details>
+ {{#if (hasStepData step)}}
+ <details class="workflows-execution-detail__step-section">
+ <summary>
+ {{i18n "discourse_workflows.executions.input"}}
+ {{#if (itemCount step.input)}}
+ <span
+ class="workflows-execution-detail__item-count"
+ >{{itemCount step.input}}
+ {{i18n "discourse_workflows.executions.items"}}</span>
+ {{/if}}
+ </summary>
+ <pre>{{formatInputData step.input}}</pre>
+ </details>
+ <details class="workflows-execution-detail__step-section">
+ <summary>
+ {{i18n "discourse_workflows.executions.output"}}
+ {{#if (itemCount step.output)}}
+ <span
+ class="workflows-execution-detail__item-count"
+ >{{itemCount step.output}}
+ {{i18n "discourse_workflows.executions.items"}}</span>
+ {{/if}}
+ </summary>
+ <pre>{{formatOutputData step.output}}</pre>
+ </details>
+ {{/if}}
</div>
</div>
{{/each}}
diff --git a/plugins/discourse-workflows/app/controllers/discourse_workflows/executions_controller.rb b/plugins/discourse-workflows/app/controllers/discourse_workflows/executions_controller.rb
index d5758bfba87..44297c2c911 100644
--- a/plugins/discourse-workflows/app/controllers/discourse_workflows/executions_controller.rb
+++ b/plugins/discourse-workflows/app/controllers/discourse_workflows/executions_controller.rb
@@ -70,7 +70,11 @@ module DiscourseWorkflows
root: false,
),
meta: {
- message_bus_last_id: message_bus_last_id,
+ message_bus_last_id:
+ DiscourseWorkflows::ExecutionProgressPublisher.subscription_start_id(
+ execution,
+ message_bus_last_id,
+ ),
},
}
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/execution_progress_publisher.rb b/plugins/discourse-workflows/lib/discourse_workflows/execution_progress_publisher.rb
index 4b73f86b1ad..744df29f540 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/execution_progress_publisher.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/execution_progress_publisher.rb
@@ -21,6 +21,12 @@ module DiscourseWorkflows
"/discourse-workflows/execution/#{execution_id}"
end
+ def self.subscription_start_id(execution, last_id)
+ return last_id if !execution.running? || execution.execution_data&.entries.present?
+
+ [last_id - MAX_BACKLOG_SIZE, 0].max
+ end
+
def self.publish_created(execution, workflow_name:)
MessageBus.publish(
EXECUTIONS_CHANNEL,
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/execution_progress_publisher_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/execution_progress_publisher_spec.rb
index 4dfba30506d..dd980a5770c 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/execution_progress_publisher_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/execution_progress_publisher_spec.rb
@@ -52,4 +52,28 @@ RSpec.describe DiscourseWorkflows::ExecutionProgressPublisher do
expect(created_messages.first.data).to include(type: "execution_created")
expect(created_messages.first.data[:execution]).to include(workflow_name: workflow.name)
end
+
+ describe ".subscription_start_id" do
+ it "returns the last id when the execution is not running" do
+ execution = Fabricate(:discourse_workflows_completed_execution, workflow:)
+
+ expect(described_class.subscription_start_id(execution, 42)).to eq(42)
+ end
+
+ it "returns the last id when the execution has stored steps" do
+ execution = Fabricate(:discourse_workflows_execution, workflow:, status: :running)
+ Fabricate(:discourse_workflows_execution_data_with_steps, execution:)
+
+ expect(described_class.subscription_start_id(execution, 42)).to eq(42)
+ end
+
+ it "replays the backlog when a running execution has no stored steps" do
+ execution = Fabricate(:discourse_workflows_execution, workflow:, status: :running)
+
+ expect(described_class.subscription_start_id(execution, 42)).to eq(0)
+ expect(described_class.subscription_start_id(execution, 250)).to eq(
+ 250 - described_class::MAX_BACKLOG_SIZE,
+ )
+ end
+ end
end
diff --git a/plugins/discourse-workflows/spec/requests/discourse_workflows/executions_controller_spec.rb b/plugins/discourse-workflows/spec/requests/discourse_workflows/executions_controller_spec.rb
index 26c2434ff05..71185abd1de 100644
--- a/plugins/discourse-workflows/spec/requests/discourse_workflows/executions_controller_spec.rb
+++ b/plugins/discourse-workflows/spec/requests/discourse_workflows/executions_controller_spec.rb
@@ -189,6 +189,33 @@ RSpec.describe DiscourseWorkflows::ExecutionsController do
expect(json.dig("meta", "message_bus_last_id")).to be_a(Integer)
end
+ it "replays the progress backlog of a running execution without stored steps" do
+ running = Fabricate(:discourse_workflows_execution, workflow:, status: :running)
+ channel = DiscourseWorkflows::ExecutionProgressPublisher.execution_channel(running.id)
+ 2.times { MessageBus.publish(channel, { type: "execution_progress" }) }
+
+ get "/admin/plugins/discourse-workflows/executions/#{running.id}.json"
+
+ expect(response.parsed_body.dig("meta", "message_bus_last_id")).to eq(
+ [
+ MessageBus.last_id(channel) -
+ DiscourseWorkflows::ExecutionProgressPublisher::MAX_BACKLOG_SIZE,
+ 0,
+ ].max,
+ )
+ end
+
+ it "only subscribes to new progress once steps are stored" do
+ channel = DiscourseWorkflows::ExecutionProgressPublisher.execution_channel(execution.id)
+ 2.times { MessageBus.publish(channel, { type: "execution_progress" }) }
+
+ get "/admin/plugins/discourse-workflows/executions/#{execution.id}.json"
+
+ expect(response.parsed_body.dig("meta", "message_bus_last_id")).to eq(
+ MessageBus.last_id(channel),
+ )
+ end
+
it "returns caller workflow data for child executions" do
target_workflow = Fabricate(:discourse_workflows_workflow, created_by: admin)
child_execution =
diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs
index 76438862ef6..55dc1c4f659 100644
--- a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs
+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs
@@ -621,6 +621,9 @@ module(
assert
.dom(".workflows-execution-detail__step-badge")
.hasText("Running", "the live step status is visible");
+ assert
+ .dom(".workflows-execution-detail__step-section")
+ .doesNotExist("input and output are not part of progress messages");
});
}
);