WorkflowMiddlewarePhase.PostWorkflow not called when Workflow is terminated
I have set up a very simple workflow, that has a pre and a post workflow step.
Everything works as expected when the workflow runs to normal completion. But if there is an exception in one of the steps, the post workflow step is totally ignored.
I have attached the sample code with 2 cases for reference.
I was expecting that the post pipeline code would still execute in the event of the workflow being terminated because of error ... or is this not the case?
I have tried attaching the the global OnStepError, and this is called as expected ... but I am not expecting that we should be putting any post workflow logic here.
So my issue is that when the exception occurs, I cannot see any other way to properly clean up the workflow.....or am I missing something?
Regards PipelineEndProblem.zip
If I am not mistaken, it appears that this is controlled in WorkFlowExecutor.DetermineNextExecutionTime where it looks as though the PostWorkflow steps will only be performed in the event that the workflow has actually completed successfully.
So if this is the way it is supposed to be by design, then this would mean that we cannot / should not use the pipeline to perform any setup/teardown ... instead we should essentially create our own mechanism (similar to what is done in the tests) to startup and teardown any allocated resources that may be used.
Or is it that the current implementation is incorrect, and the pipeline processes should be given an opportunity to be applied irrespective of whether it is a successful completion or not?
Appreciate if anyone has any other thoughts/experiences on this.
Even my team is facing this issue when we try to manually terminate the workflow. The PostWorkflow isn't working in this case
After reading the first paragraph https://workflow-core.readthedocs.io/en/latest/workflow-middleware/, and looking at the code. I came to the conclusion that this is probably by design ... although I cannot imagine why.
It states that Middleware that run before/after workflows start/complete .. since it does not talk about Terminating, then it might be by design.
I do not know what solution you (and your team) have come up with ... but what I did was to throw away the middleware processing, and create a separate object to wrap the workflow. This is will:
- Create a loop of its own that waits for the processing of the workflow to either complete, terminate, or timeout
- Listen to the hub for any exception
- Define its own custom event that can bundle together the information from the conclusion of the workflow (e.g. output data, file, exception, etc)
- Manage any setup/tear down that might need to be done.
In my case, I do not have any complex setup and teardown that needs to be done, but I am allocating external resources so it is critical that I dispose of them correctly.
Hope that this helps.
We were trying have a Post IWorkflowMiddleware that is logging the status of workflows including steps that were retried and failed similar to the PrintWorkflowSummaryMiddleware example here:
https://workflow-core.readthedocs.io/en/latest/workflow-middleware/
Unfortunately because of this, it means that this middleware pattern is useless when we need to log summary details about the workflow failure/termination (i.e. when we need it the most).
I've had to resort to try/catch blocks in StepMiddleware to do this logging instead, which isn't as ideal.
Closing as not planned — this has been open for several years without recent progress. Please open a new issue if this is still relevant on a current Workflow Core release.