Skip to content

Conversation

hanna-cirilla
Copy link
Contributor

@hanna-cirilla hanna-cirilla commented Aug 12, 2023

Describe the change
As described in #1097 a workflow that ends in an EndStep does not lead to the WorkflowCompleted LifeCycleEvent being published because DetermineNextExecutionTime returns too early.
This PR remedies that by sending the event also in case of an early return from DetermineNextExecutionTime.

Describe your implementation or design
Extracted publishing of WorkflowCompleted into a separate method and added a call to that function before the early return if workflow is completed.

Tests
Yes, added a failing unit test that is green after the implementation is changed.

Breaking change
No

Additional context

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where workflows ending with an EndStep were not publishing the WorkflowCompleted lifecycle event. The issue occurred because DetermineNextExecutionTime returned early for completed workflows without sending the event.

  • Extracted workflow completion event publishing into a separate method PublishWorkflowCompleted
  • Added the event publication before the early return when workflow status is complete
  • Added a unit test to verify the fix works correctly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/WorkflowCore.UnitTests/Services/WorkflowExecutorFixture.cs Added unit test to verify WorkflowCompleted event is published when workflow ends
src/WorkflowCore/Services/WorkflowExecutor.cs Fixed missing event publication by extracting PublishWorkflowCompleted method and calling it before early return

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +272 to 276
private void PublishWorkflowCompleted(WorkflowInstance workflow)
{
_publisher.PublishNotification(new WorkflowCompleted
{
EventTimeUtc = _datetimeProvider.UtcNow,
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PublishWorkflowCompleted method is incomplete. The WorkflowCompleted object initialization is not closed with a closing brace and semicolon, and the method body is not properly closed.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WorkflowExecutor is not sending LifeCycleEvents.WorkflowCompleted when Workflow is marked with IStepBuilder.EndWorkflow
2 participants