Skip to content

Commit ae4cb9a

Browse files
authored
doc: Revisit doc on [Activity|ChildWorkflow]CancellationTypes + other minor lints (#1892)
1 parent 1586019 commit ae4cb9a

17 files changed

Lines changed: 174 additions & 89 deletions

packages/client/src/schedule-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface ScheduleOptions<A extends ScheduleOptionsAction = ScheduleOptio
3131
* running. This can be changed after a Schedule has taken some Actions, and some changes might produce
3232
* unintuitive results. In general, the later policy overrides the earlier policy.
3333
*
34-
* @default {@link ScheduleOverlapPolicy.SKIP}
34+
* @default ScheduleOverlapPolicy.SKIP
3535
*/
3636
overlap?: ScheduleOverlapPolicy;
3737

packages/client/src/task-queue-client.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ export class TaskQueueClient extends BaseClient {
173173
*/
174174
export type ReachabilityOptions = RequireAtLeastOne<BaseReachabilityOptions, 'buildIds' | 'taskQueues'>;
175175

176+
/**
177+
* There are different types of reachability:
178+
* - `NEW_WORKFLOWS`: The Build Id might be used by new workflows
179+
* - `EXISTING_WORKFLOWS` The Build Id might be used by open workflows and/or closed workflows.
180+
* - `OPEN_WORKFLOWS` The Build Id might be used by open workflows
181+
* - `CLOSED_WORKFLOWS` The Build Id might be used by closed workflows
182+
*/
176183
export const ReachabilityType = {
177184
/** The Build Id might be used by new workflows. */
178185
NEW_WORKFLOWS: 'NEW_WORKFLOWS',
@@ -186,14 +193,6 @@ export const ReachabilityType = {
186193
/** The Build Id might be used by closed workflows. */
187194
CLOSED_WORKFLOWS: 'CLOSED_WORKFLOWS',
188195
} as const;
189-
190-
/**
191-
* There are different types of reachability:
192-
* - `NEW_WORKFLOWS`: The Build Id might be used by new workflows
193-
* - `EXISTING_WORKFLOWS` The Build Id might be used by open workflows and/or closed workflows.
194-
* - `OPEN_WORKFLOWS` The Build Id might be used by open workflows
195-
* - `CLOSED_WORKFLOWS` The Build Id might be used by closed workflows
196-
*/
197196
export type ReachabilityType = (typeof ReachabilityType)[keyof typeof ReachabilityType];
198197

199198
export const [encodeTaskReachability, decodeTaskReachability] = makeProtoEnumConverters<

packages/common/src/activity-options.ts

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,57 @@ import { VersioningIntent } from './versioning-intent';
55
import { makeProtoEnumConverters } from './internal-workflow';
66
import { Priority } from './priority';
77

8+
// Note: The types defined in this file are here for legacy reasons. They should have been defined
9+
// in the 'workflow' package, instead of 'common'. They are now reexported from the 'workflow'
10+
// package, which is the preferred way to import them, but we unfortunately can't remove them from
11+
// here as that would be a breaking change.
12+
13+
/**
14+
* Determines:
15+
* - whether cancellation requests should be propagated from the current Workflow to the Activity; and
16+
* - when should the Activity cancellation be reported to Workflow (i.e. at which moment should the
17+
* Activity call's promise fail with an `ActivityFailure`, with `cause` set to a `CancelledFailure`).
18+
*
19+
* Note that this setting only applies to cancellation originating from cancellation being
20+
* externally requested on the Workflow itself, or from internal cancellation of the
21+
* `CancellationScope` in which the Activity call was made. Termination of a Workflow Execution
22+
* always results in cancellation of its outstanding Activity executions, regardless of those
23+
* Activities' {@link ActivityCancellationType} settings.
24+
*
25+
* @default ActivityCancellationType.WAIT_CANCELLATION_COMPLETED
26+
*/
827
export const ActivityCancellationType = {
28+
/**
29+
* Do not propagate cancellation requests to the Activity, and immediately report cancellation
30+
* to the caller.
31+
*/
32+
ABANDON: 'ABANDON',
33+
34+
/**
35+
* Propagate cancellation request from the Workflow to the Activity, yet _immediately_ report
36+
* cancellation to the caller, i.e. without waiting for the server to confirm the cancellation
37+
* request.
38+
*
39+
* Note that this cancellation type provides no guarantee, from the Workflow-side, that the
40+
* cancellation request will actually be delivered to the Activity; e.g. the calling Workflow
41+
* may exit before the delivery is completed, or the Activity may complete (either successfully
42+
* or uncessfully) before the cancellation is delivered, resulting in a situation where the
43+
* workflow thinks the activity was cancelled, but the activity actually completed successfully.
44+
*
45+
* To ensure that the Workflow is properly informed of the Activity's final state (i.e. either
46+
* completion or cancellation), use {@link WAIT_CANCELLATION_COMPLETED}.
47+
*/
948
TRY_CANCEL: 'TRY_CANCEL',
49+
50+
/**
51+
* Propagate cancellation request from the Workflow to the Activity, and wait for the activity
52+
* to complete its execution (either successfully, uncessfully, or as cancelled).
53+
*
54+
* Note that the Activity must heartbeat to receive a cancellation notification. This can block
55+
* the Workflow's cancellation for a long time if the Activity doesn't heartbeat or chooses to
56+
* ignore the cancellation request.
57+
*/
1058
WAIT_CANCELLATION_COMPLETED: 'WAIT_CANCELLATION_COMPLETED',
11-
ABANDON: 'ABANDON',
1259
} as const;
1360
export type ActivityCancellationType = (typeof ActivityCancellationType)[keyof typeof ActivityCancellationType];
1461

@@ -93,12 +140,18 @@ export interface ActivityOptions {
93140
scheduleToCloseTimeout?: Duration;
94141

95142
/**
96-
* Determines what the SDK does when the Activity is cancelled.
97-
* - `TRY_CANCEL` - Initiate a cancellation request and immediately report cancellation to the workflow.
98-
* - `WAIT_CANCELLATION_COMPLETED` - Wait for activity cancellation completion. Note that activity must heartbeat to receive a
99-
* cancellation notification. This can block the cancellation for a long time if activity doesn't
100-
* heartbeat or chooses to ignore the cancellation request.
101-
* - `ABANDON` - Do not request cancellation of the activity and immediately report cancellation to the workflow.
143+
* Determines:
144+
* - whether cancellation requests should be propagated from the current Workflow to the Activity; and
145+
* - when should the Activity cancellation be reported to Workflow (i.e. at which moment should the
146+
* Activity call's promise fail with an `ActivityFailure`, with `cause` set to a `CancelledFailure`).
147+
*
148+
* Note that this setting only applies to cancellation originating from cancellation being
149+
* externally requested on the Workflow itself, or from internal cancellation of the
150+
* `CancellationScope` in which the Activity call was made. Termination of a Workflow Execution
151+
* always results in cancellation of its outstanding Activity executions, regardless of those
152+
* Activities' {@link ActivityCancellationType} settings.
153+
*
154+
* @default ActivityCancellationType.WAIT_CANCELLATION_COMPLETED
102155
*/
103156
cancellationType?: ActivityCancellationType;
104157

@@ -193,12 +246,18 @@ export interface LocalActivityOptions {
193246
localRetryThreshold?: Duration;
194247

195248
/**
196-
* Determines what the SDK does when the Activity is cancelled.
197-
* - `TRY_CANCEL` - Initiate a cancellation request and immediately report cancellation to the workflow.
198-
* - `WAIT_CANCELLATION_COMPLETED` - Wait for activity cancellation completion. Note that activity must heartbeat to receive a
199-
* cancellation notification. This can block the cancellation for a long time if activity doesn't
200-
* heartbeat or chooses to ignore the cancellation request.
201-
* - `ABANDON` - Do not request cancellation of the activity and immediately report cancellation to the workflow.
249+
* Determines:
250+
* - whether cancellation requests should be propagated from the current Workflow to the Activity; and
251+
* - when should the Activity cancellation be reported to Workflow (i.e. at which moment should the
252+
* Activity call's promise fail with an `ActivityFailure`, with `cause` set to a `CancelledFailure`).
253+
*
254+
* Note that this setting only applies to cancellation originating from cancellation being
255+
* externally requested on the Workflow itself, or from internal cancellation of the
256+
* `CancellationScope` in which the Activity call was made. Termination of a Workflow Execution
257+
* always results in cancellation of its outstanding Activity executions, regardless of those
258+
* Activities' {@link ActivityCancellationType} settings.
259+
*
260+
* @default ActivityCancellationType.WAIT_CANCELLATION_COMPLETED
202261
*/
203262
cancellationType?: ActivityCancellationType;
204263

packages/common/src/converter/failure-converter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const NexusHandlerErrorRetryBehavior = {
3030
RETRYABLE: 'RETRYABLE',
3131
NON_RETRYABLE: 'NON_RETRYABLE',
3232
} as const;
33-
3433
type NexusHandlerErrorRetryBehavior =
3534
(typeof NexusHandlerErrorRetryBehavior)[keyof typeof NexusHandlerErrorRetryBehavior];
3635

packages/common/src/failure.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ export const [encodeRetryState, decodeRetryState] = makeProtoEnumConverters<
112112
export const ApplicationFailureCategory = {
113113
BENIGN: 'BENIGN',
114114
} as const;
115-
116115
export type ApplicationFailureCategory = (typeof ApplicationFailureCategory)[keyof typeof ApplicationFailureCategory];
117116

118117
export const [encodeApplicationFailureCategory, decodeApplicationFailureCategory] = makeProtoEnumConverters<

packages/common/src/internal-workflow/enums-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { Exact, RemovePrefix, UnionToIntersection } from '../type-helpers';
1010
* Newly introduced enums should follow the following pattern:
1111
*
1212
* ```ts
13-
* type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
1413
* const ParentClosePolicy = {
1514
* TERMINATE: 'TERMINATE',
1615
* ABANDON: 'ABANDON',
1716
* REQUEST_CANCEL: 'REQUEST_CANCEL',
1817
* } as const;
18+
* type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
1919
*
2020
* const [encodeParentClosePolicy, decodeParentClosePolicy] = //
2121
* makeProtoEnumConverters<

packages/common/src/search-attributes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const SearchAttributeType = {
1717
DATETIME: 'DATETIME',
1818
KEYWORD_LIST: 'KEYWORD_LIST',
1919
} as const;
20-
2120
export type SearchAttributeType = (typeof SearchAttributeType)[keyof typeof SearchAttributeType];
2221

2322
// Note: encodeSearchAttributeIndexedValueType exported for use in tests to register search attributes

packages/common/src/workflow-options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export const [encodeWorkflowIdReusePolicy, decodeWorkflowIdReusePolicy] = makePr
9393
*
9494
* *Note: It is never possible to have two _actively running_ Workflows with the same ID.*
9595
*/
96-
export type WorkflowIdConflictPolicy = (typeof WorkflowIdConflictPolicy)[keyof typeof WorkflowIdConflictPolicy];
9796
export const WorkflowIdConflictPolicy = {
9897
/**
9998
* Do not start a new Workflow. Instead raise a `WorkflowExecutionAlreadyStartedError`.
@@ -110,6 +109,7 @@ export const WorkflowIdConflictPolicy = {
110109
*/
111110
TERMINATE_EXISTING: 'TERMINATE_EXISTING',
112111
} as const;
112+
export type WorkflowIdConflictPolicy = (typeof WorkflowIdConflictPolicy)[keyof typeof WorkflowIdConflictPolicy];
113113

114114
export const [encodeWorkflowIdConflictPolicy, decodeWorkflowIdConflictPolicy] = makeProtoEnumConverters<
115115
temporal.api.enums.v1.WorkflowIdConflictPolicy,
@@ -133,7 +133,7 @@ export interface BaseWorkflowOptions {
133133
*
134134
* *Note: It is not possible to have two actively running Workflows with the same ID.*
135135
*
136-
* @default {@link WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE}
136+
* @default WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
137137
*/
138138
workflowIdReusePolicy?: WorkflowIdReusePolicy;
139139

@@ -142,7 +142,7 @@ export interface BaseWorkflowOptions {
142142
*
143143
* *Note: It is not possible to have two actively running Workflows with the same ID.*
144144
*
145-
* @default {@link WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED}
145+
* @default WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED
146146
*/
147147
workflowIdConflictPolicy?: WorkflowIdConflictPolicy;
148148

packages/nexus/src/token.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/**
2+
* OperationTokenType is used to identify the type of Operation token.
3+
* Currently, we only have one type of Operation token: WorkflowRun.
4+
*
25
* @internal
36
* @hidden
47
*/
@@ -24,11 +27,6 @@ export interface WorkflowRunOperationToken {
2427
*/
2528
wid: string;
2629
}
27-
28-
/**
29-
* OperationTokenType is used to identify the type of Operation token.
30-
* Currently, we only have one type of Operation token: WorkflowRun.
31-
*/
3230
type OperationTokenType = (typeof OperationTokenType)[keyof typeof OperationTokenType];
3331

3432
/**

packages/test/src/test-enums-helpers.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
44

55
// ASSERTION: There MUST be a corresponding `KEY: 'KEY'` in the const object of strings enum (must be present)
66
{
7-
type ParentClosePolicyMissingEntry =
8-
(typeof ParentClosePolicyMissingEntry)[keyof typeof ParentClosePolicyMissingEntry];
97
const ParentClosePolicyMissingEntry = {
108
TERMINATE: 'TERMINATE',
119
// ABANDON: 'ABANDON', // Missing entry!
1210
REQUEST_CANCEL: 'REQUEST_CANCEL',
1311
} as const;
12+
type ParentClosePolicyMissingEntry =
13+
(typeof ParentClosePolicyMissingEntry)[keyof typeof ParentClosePolicyMissingEntry];
1414

1515
makeProtoEnumConverters<
1616
coresdk.child_workflow.ParentClosePolicy,
@@ -30,13 +30,13 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
3030

3131
// ASSERTION: There MUST be a corresponding `KEY: 'KEY'` in the const object of strings enum (must have correct value)
3232
{
33-
type ParentClosePolicyIncorectEntry =
34-
(typeof ParentClosePolicyIncorectEntry)[keyof typeof ParentClosePolicyIncorectEntry];
3533
const ParentClosePolicyIncorectEntry = {
3634
TERMINATE: 'TERMINATE',
3735
ABANDON: 'INCORRECT', // Incorrect entry!
3836
REQUEST_CANCEL: 'REQUEST_CANCEL',
3937
} as const;
38+
type ParentClosePolicyIncorectEntry =
39+
(typeof ParentClosePolicyIncorectEntry)[keyof typeof ParentClosePolicyIncorectEntry];
4040

4141
makeProtoEnumConverters<
4242
coresdk.child_workflow.ParentClosePolicy,
@@ -57,8 +57,6 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
5757

5858
// ASSERTION: There MAY be a corresponding `PREFIX_KEY: 'KEY'` in the const object of strings enum (may be present)
5959
{
60-
type ParentClosePolicyWithPrefixedEntries =
61-
(typeof ParentClosePolicyWithPrefixedEntries)[keyof typeof ParentClosePolicyWithPrefixedEntries];
6260
const ParentClosePolicyWithPrefixedEntries = {
6361
TERMINATE: 'TERMINATE',
6462
ABANDON: 'ABANDON',
@@ -68,6 +66,8 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
6866
PARENT_CLOSE_POLICY_ABANDON: 'ABANDON',
6967
PARENT_CLOSE_POLICY_REQUEST_CANCEL: 'REQUEST_CANCEL',
7068
} as const;
69+
type ParentClosePolicyWithPrefixedEntries =
70+
(typeof ParentClosePolicyWithPrefixedEntries)[keyof typeof ParentClosePolicyWithPrefixedEntries];
7171

7272
makeProtoEnumConverters<
7373
coresdk.child_workflow.ParentClosePolicy,
@@ -88,13 +88,13 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
8888

8989
// ASSERTION: There MAY be a corresponding `PREFIX_KEY: 'KEY'` in the const object of strings enum (may not be present)
9090
{
91-
type ParentClosePolicyWithoutPrefixedEntries =
92-
(typeof ParentClosePolicyWithoutPrefixedEntries)[keyof typeof ParentClosePolicyWithoutPrefixedEntries];
9391
const ParentClosePolicyWithoutPrefixedEntries = {
9492
TERMINATE: 'TERMINATE',
9593
ABANDON: 'ABANDON',
9694
REQUEST_CANCEL: 'REQUEST_CANCEL',
9795
} as const;
96+
type ParentClosePolicyWithoutPrefixedEntries =
97+
(typeof ParentClosePolicyWithoutPrefixedEntries)[keyof typeof ParentClosePolicyWithoutPrefixedEntries];
9898

9999
makeProtoEnumConverters<
100100
coresdk.child_workflow.ParentClosePolicy,
@@ -115,8 +115,6 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
115115

116116
// ASSERTION: There MAY be a corresponding `PREFIX_KEY: 'KEY'` in the const object of strings enum (if present, must have correct value)
117117
{
118-
type ParentClosePolicyWithPrefixedEntries =
119-
(typeof ParentClosePolicyWithPrefixedEntries)[keyof typeof ParentClosePolicyWithPrefixedEntries];
120118
const ParentClosePolicyWithPrefixedEntries = {
121119
TERMINATE: 'TERMINATE',
122120
ABANDON: 'ABANDON',
@@ -126,6 +124,8 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
126124
PARENT_CLOSE_POLICY_ABANDON: 'ABANDON',
127125
PARENT_CLOSE_POLICY_REQUEST_CANCEL: 'INCORRECT', // Incorrect entry!
128126
} as const;
127+
type ParentClosePolicyWithPrefixedEntries =
128+
(typeof ParentClosePolicyWithPrefixedEntries)[keyof typeof ParentClosePolicyWithPrefixedEntries];
129129

130130
makeProtoEnumConverters<
131131
coresdk.child_workflow.ParentClosePolicy,
@@ -146,7 +146,6 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
146146
}
147147

148148
{
149-
type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
150149
const ParentClosePolicy = {
151150
TERMINATE: 'TERMINATE',
152151
ABANDON: 'ABANDON',
@@ -157,6 +156,7 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
157156
PARENT_CLOSE_POLICY_ABANDON: 'ABANDON',
158157
PARENT_CLOSE_POLICY_REQUEST_CANCEL: 'REQUEST_CANCEL',
159158
} as const;
159+
type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
160160

161161
// ASSERTION: There MUST be a corresponding `KEY: number` in the mapping table (must be there)
162162
makeProtoEnumConverters<
@@ -300,13 +300,13 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
300300

301301
// ASSERTION: The const object of strings enum MUST NOT contain any other keys than the ones mandated or optionally allowed above.
302302
{
303-
type ParentClosePolicyWithExtra = (typeof ParentClosePolicyWithExtra)[keyof typeof ParentClosePolicyWithExtra];
304303
const ParentClosePolicyWithExtra = {
305304
TERMINATE: 'TERMINATE',
306305
ABANDON: 'ABANDON',
307306
REQUEST_CANCEL: 'REQUEST_CANCEL',
308307
EXTRA: 'EXTRA', // Extra entry!
309308
} as const;
309+
type ParentClosePolicyWithExtra = (typeof ParentClosePolicyWithExtra)[keyof typeof ParentClosePolicyWithExtra];
310310

311311
makeProtoEnumConverters<
312312
coresdk.child_workflow.ParentClosePolicy,
@@ -327,7 +327,6 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
327327
}
328328

329329
{
330-
type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
331330
const ParentClosePolicy = {
332331
TERMINATE: 'TERMINATE',
333332
ABANDON: 'ABANDON',
@@ -338,6 +337,7 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
338337
PARENT_CLOSE_POLICY_ABANDON: 'ABANDON',
339338
PARENT_CLOSE_POLICY_REQUEST_CANCEL: 'REQUEST_CANCEL',
340339
} as const;
340+
type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
341341

342342
// ASSERTION: The mapping table MUST NOT contain any other keys than the ones mandated above
343343
makeProtoEnumConverters<
@@ -416,7 +416,6 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
416416

417417
// Functionnal tests
418418
{
419-
type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
420419
const ParentClosePolicy = {
421420
TERMINATE: 'TERMINATE',
422421
ABANDON: 'ABANDON',
@@ -427,6 +426,7 @@ import { makeProtoEnumConverters as makeProtoEnumConverters } from '@temporalio/
427426
PARENT_CLOSE_POLICY_ABANDON: 'ABANDON',
428427
PARENT_CLOSE_POLICY_REQUEST_CANCEL: 'REQUEST_CANCEL',
429428
} as const;
429+
type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
430430

431431
const [encodeParentClosePolicy, decodeParentClosePolicy] = //
432432
makeProtoEnumConverters<

0 commit comments

Comments
 (0)