workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

[Feature] Add scope support for workflow

Open ling921 opened this issue 1 year ago • 2 comments

Describe the change

This pull request is to make Step to only obtain services from a specific scope.

Related issues: #1231 #846

Describe your implementation or design

Add a method to IWorkflowController called StartWorkflowWithScope, which accept an additional parameter IServiceScope, and then save it in WorkflowInstance

Tests

Yes

Breaking change

No

Additional context

None

ling921 avatar Jan 27 '24 07:01 ling921

@ling921 thanks for the effort. Unfortunately, this does not make sense to wrap an entire workflow in a scope. When the workflow is executed, the entire thing "may" be executed all at once, or it may be partially executed and continue several days later, or on another machine. So we cannot preserve the scope across these time and node boundaries. We do wrap step executions within a scope here

danielgerlag avatar Jan 27 '24 23:01 danielgerlag

I understand this, and I haven't changed its default behavior. If users expect wrokflow steps to be executed within a certain scope, they should manage the creation and disposal of the scope themselves.

Also, I think the design of this scope is meaningful. I can define a scoped service to track or change the step's execution, and even share some unmanaged resources, etc. All of these are more suitable to be written in a service rather than within TData.

The primary challenge is ensuring the effective management of the scope, especially regarding proper disposal. In my current design, it is imperative for the user to proficiently handle scope disposal. With correct scope disposal, I believe there should be no issues with long-term retention.

There may be a more optimal design that can achieve this.

ling921 avatar Jan 28 '24 03:01 ling921