Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcdec2d

Browse files
authored
docs: Document ParentClosePolicy, ChildWorkflowCancellationType, and WorkflowIdReusePolicy (temporalio#716)
1 parent 3182599 commit fcdec2d

File tree

2 files changed

+90
-11
lines changed

2 files changed

+90
-11
lines changed

packages/internal-workflow-common/src/workflow-options.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,47 @@ import { checkExtends, Replace } from './type-helpers';
66

77
// Avoid importing the proto implementation to reduce workflow bundle size
88
// Copied from temporal.api.enums.v1.WorkflowIdReusePolicy
9+
/**
10+
* Concept: [Workflow Id Reuse Policy](https://docs.temporal.io/concepts/what-is-a-workflow-id-reuse-policy/)
11+
*
12+
* Whether a Workflow can be started with a Workflow Id of a Closed Workflow.
13+
*
14+
* *Note: A Workflow can never be started with a Workflow Id of a Running Workflow.*
15+
*/
916
export enum WorkflowIdReusePolicy {
17+
/**
18+
* No need to use this.
19+
*
20+
* (If a `WorkflowIdReusePolicy` is set to this, or is not set at all, the default value will be used.)
21+
*/
1022
WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED = 0,
23+
24+
/**
25+
* The Workflow can be started if the previous Workflow is in a Closed state.
26+
* @default
27+
*/
1128
WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE = 1,
29+
30+
/**
31+
* The Workflow can be started if the previous Workflow is in a Closed state that is not Completed.
32+
*/
1233
WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY = 2,
34+
35+
/**
36+
* The Workflow cannot be started.
37+
*/
1338
WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE = 3,
1439
}
1540

1641
checkExtends<temporal.api.enums.v1.WorkflowIdReusePolicy, WorkflowIdReusePolicy>();
1742

1843
export interface BaseWorkflowOptions {
1944
/**
20-
* Specifies server behavior if a completed workflow with the same id exists. Note that under no
21-
* conditions Temporal allows two workflows with the same namespace and workflow id run
22-
* simultaneously.
23-
* ALLOW_DUPLICATE_FAILED_ONLY is a default value. It means that workflow can start if
24-
* previous run failed or was canceled or terminated.
25-
* ALLOW_DUPLICATE allows new run independently of the previous run closure status.
26-
* REJECT_DUPLICATE doesn't allow new run independently of the previous run closure status.
45+
* Whether a Workflow can be started with a Workflow Id of a Closed Workflow.
46+
*
47+
* *Note: A Workflow can never be started with a Workflow Id of a Running Workflow.*
48+
*
49+
* @default {@link WorkflowIdReusePolicy.ALLOW_DUPLICATE_FAILED_ONLY}
2750
*/
2851
workflowIdReusePolicy?: WorkflowIdReusePolicy;
2952

packages/workflow/src/interfaces.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,69 @@ export interface ContinueAsNewOptions {
165165
searchAttributes?: SearchAttributes;
166166
}
167167

168+
/**
169+
* Specifies:
170+
* - whether cancellation requests are sent to the Child
171+
* - whether and when a {@link CanceledFailure} is thrown from {@link executeChild} or
172+
* {@link ChildWorkflowHandle.result}
173+
*
174+
* @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
175+
*/
168176
export enum ChildWorkflowCancellationType {
177+
/**
178+
* Don't send a cancellation request to the Child.
179+
*/
169180
ABANDON = 0,
181+
182+
/**
183+
* Send a cancellation request to the Child. Immediately throw the error.
184+
*/
170185
TRY_CANCEL = 1,
186+
187+
/**
188+
* Send a cancellation request to the Child. The Child may respect cancellation, in which case an error will be thrown
189+
* when cancellation has completed, and {@link isCancellation}(error) will be true. On the other hand, the Child may
190+
* ignore the cancellation request, in which case an error might be thrown with a different cause, or the Child may
191+
* complete successfully.
192+
*
193+
* @default
194+
*/
171195
WAIT_CANCELLATION_COMPLETED = 2,
196+
197+
/**
198+
* Send a cancellation request to the Child. Throw the error once the Server receives the Child cancellation request.
199+
*/
172200
WAIT_CANCELLATION_REQUESTED = 3,
173201
}
174202

175203
checkExtends<coresdk.child_workflow.ChildWorkflowCancellationType, ChildWorkflowCancellationType>();
176204

205+
/**
206+
* Concept: [Parent Close Policy](https://docs.temporal.io/concepts/what-is-a-parent-close-policy/)
207+
*
208+
* How a Child Workflow reacts to the Parent Workflow reaching a Closed state.
209+
*/
177210
export enum ParentClosePolicy {
211+
/**
212+
* If a `ParentClosePolicy` is set to this, or is not set at all, the server default value will be used.
213+
*/
178214
PARENT_CLOSE_POLICY_UNSPECIFIED = 0,
215+
216+
/**
217+
* When the Parent is Closed, the Child is Terminated.
218+
*
219+
* @default
220+
*/
179221
PARENT_CLOSE_POLICY_TERMINATE = 1,
222+
223+
/**
224+
* When the Parent is Closed, nothing is done to the Child.
225+
*/
180226
PARENT_CLOSE_POLICY_ABANDON = 2,
227+
228+
/**
229+
* When the Parent is Closed, the Child is Cancelled.
230+
*/
181231
PARENT_CLOSE_POLICY_REQUEST_CANCEL = 3,
182232
}
183233

@@ -198,13 +248,19 @@ export interface ChildWorkflowOptions extends CommonWorkflowOptions {
198248
taskQueue?: string;
199249

200250
/**
201-
* In case of a child workflow cancellation it fails with a CanceledFailure.
202-
* The type defines at which point the exception is thrown.
203-
* @default ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED
251+
* Specifies:
252+
* - whether cancellation requests are sent to the Child
253+
* - whether and when an error is thrown from {@link executeChild} or
254+
* {@link ChildWorkflowHandle.result}
255+
*
256+
* @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
204257
*/
205258
cancellationType?: ChildWorkflowCancellationType;
259+
206260
/**
207-
* Specifies how this workflow reacts to the death of the parent workflow.
261+
* Specifies how the Child reacts to the Parent Workflow reaching a Closed state.
262+
*
263+
* @default {@link ParentClosePolicy.PARENT_CLOSE_POLICY_TERMINATE}
208264
*/
209265
parentClosePolicy?: ParentClosePolicy;
210266
}

0 commit comments

Comments
 (0)