@temporalio/activity 1.0.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +44 -13
- package/lib/index.js +38 -10
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +44 -13
package/lib/index.d.ts
CHANGED
|
@@ -15,19 +15,45 @@
|
|
|
15
15
|
*
|
|
16
16
|
* ### Cancellation
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* Activity Cancellation:
|
|
19
|
+
*
|
|
20
|
+
* - lets the Activity know it doesn't need to keep doing work, and
|
|
21
|
+
* - gives the Activity time to clean up any resources it has created.
|
|
22
|
+
*
|
|
23
|
+
* Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
|
|
24
|
+
* (which can't heartbeat but receive Cancellation anyway).
|
|
25
|
+
*
|
|
26
|
+
* An Activity may receive Cancellation if:
|
|
27
|
+
*
|
|
28
|
+
* - The Workflow scope containing the Activity call was requested to be Cancelled and
|
|
29
|
+
* {@link ActivityOptions.cancellationType} was **not** set to {@link ActivityCancellationType.ABANDON}. The scope can
|
|
30
|
+
* be cancelled in either of the following ways:
|
|
31
|
+
* - The entire Workflow was Cancelled (via {@link WorkflowHandle.cancel}).
|
|
32
|
+
* - Calling {@link CancellationScope.cancel}) from inside a Workflow.
|
|
33
|
+
* - The Worker has started to shut down. Shutdown is initiated by either:
|
|
34
|
+
* - One of the {@link RuntimeOptions.shutdownSignals} was sent to the process.
|
|
35
|
+
* - {@link Worker.shutdown | `Worker.shutdown()`} was called.
|
|
36
|
+
* - The Activity was considered failed by the Server because any of the Activity timeouts have triggered (for example,
|
|
37
|
+
* the Server didn't receive a heartbeat within the {@link ActivityOptions.heartbeatTimeout}). The
|
|
38
|
+
* {@link CancelledFailure} will have `message: 'TIMED_OUT'`.
|
|
39
|
+
* - An Activity sends a heartbeat with `Context.current().heartbeat()` and the heartbeat details can't be converted by
|
|
40
|
+
* the Worker's configured {@link DataConverter}.
|
|
41
|
+
* - The Workflow Run reached a {@link https://docs.temporal.io/workflows#status | Closed state}, in which case the
|
|
42
|
+
* {@link CancelledFailure} will have `message: 'NOT_FOUND'`.
|
|
43
|
+
*
|
|
44
|
+
* The reason for the Cancellation is available at {@link CancelledFailure.message} or
|
|
45
|
+
* {@link Context#cancellationSignal | Context.cancellationSignal.reason}.
|
|
46
|
+
*
|
|
47
|
+
* There are two ways to handle Activity Cancellation:
|
|
19
48
|
*
|
|
20
|
-
* There are two ways to handle Activity cancellation:
|
|
21
49
|
* 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
|
|
22
|
-
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a
|
|
23
|
-
* {@link CancelledFailure}.
|
|
50
|
+
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
|
|
24
51
|
* 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
|
|
25
|
-
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that
|
|
26
|
-
* supports it.
|
|
52
|
+
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
|
|
27
53
|
*
|
|
28
54
|
* ### Examples
|
|
29
55
|
*
|
|
30
|
-
* #### An Activity that sends progress heartbeats and can be
|
|
56
|
+
* #### An Activity that sends progress heartbeats and can be Cancelled
|
|
31
57
|
*
|
|
32
58
|
* <!--SNIPSTART typescript-activity-fake-progress-->
|
|
33
59
|
* <!--SNIPEND-->
|
|
@@ -52,7 +78,7 @@ UntypedActivities, errorMessage, errorCode, } from '@temporalio/internal-workflo
|
|
|
52
78
|
* Throw this error from an Activity in order to make the Worker forget about this Activity.
|
|
53
79
|
*
|
|
54
80
|
* The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
|
|
55
|
-
* {@link
|
|
81
|
+
* {@link Client.activity}.
|
|
56
82
|
*
|
|
57
83
|
* @example
|
|
58
84
|
*
|
|
@@ -133,12 +159,15 @@ export interface Info {
|
|
|
133
159
|
*/
|
|
134
160
|
heartbeatTimeoutMs?: number;
|
|
135
161
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
162
|
+
* The {@link Context.heartbeat | details} from the last recorded heartbeat from the last attempt of this Activity.
|
|
163
|
+
*
|
|
164
|
+
* Use this to resume your Activity from a checkpoint.
|
|
138
165
|
*/
|
|
139
166
|
heartbeatDetails: any;
|
|
140
167
|
/**
|
|
141
|
-
* Task
|
|
168
|
+
* Task Queue the Activity is scheduled in.
|
|
169
|
+
*
|
|
170
|
+
* For Local Activities, this is set to the Workflow's Task Queue.
|
|
142
171
|
*/
|
|
143
172
|
taskQueue: string;
|
|
144
173
|
}
|
|
@@ -198,7 +227,9 @@ export declare class Context {
|
|
|
198
227
|
* attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
|
|
199
228
|
* {@link TimeoutFailure.lastHeartbeatDetails}.
|
|
200
229
|
*
|
|
201
|
-
*
|
|
230
|
+
* Calling `heartbeat()` from a Local Activity has no effect.
|
|
231
|
+
*
|
|
232
|
+
* Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
|
|
202
233
|
*/
|
|
203
234
|
heartbeat(details?: unknown): void;
|
|
204
235
|
/**
|
|
@@ -209,7 +240,7 @@ export declare class Context {
|
|
|
209
240
|
static current(): Context;
|
|
210
241
|
/**
|
|
211
242
|
* Helper function for sleeping in an Activity.
|
|
212
|
-
* @param ms Sleep duration:
|
|
243
|
+
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
213
244
|
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
|
|
214
245
|
*/
|
|
215
246
|
sleep(ms: number | string): Promise<void>;
|
package/lib/index.js
CHANGED
|
@@ -16,19 +16,45 @@
|
|
|
16
16
|
*
|
|
17
17
|
* ### Cancellation
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* Activity Cancellation:
|
|
20
|
+
*
|
|
21
|
+
* - lets the Activity know it doesn't need to keep doing work, and
|
|
22
|
+
* - gives the Activity time to clean up any resources it has created.
|
|
23
|
+
*
|
|
24
|
+
* Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
|
|
25
|
+
* (which can't heartbeat but receive Cancellation anyway).
|
|
26
|
+
*
|
|
27
|
+
* An Activity may receive Cancellation if:
|
|
28
|
+
*
|
|
29
|
+
* - The Workflow scope containing the Activity call was requested to be Cancelled and
|
|
30
|
+
* {@link ActivityOptions.cancellationType} was **not** set to {@link ActivityCancellationType.ABANDON}. The scope can
|
|
31
|
+
* be cancelled in either of the following ways:
|
|
32
|
+
* - The entire Workflow was Cancelled (via {@link WorkflowHandle.cancel}).
|
|
33
|
+
* - Calling {@link CancellationScope.cancel}) from inside a Workflow.
|
|
34
|
+
* - The Worker has started to shut down. Shutdown is initiated by either:
|
|
35
|
+
* - One of the {@link RuntimeOptions.shutdownSignals} was sent to the process.
|
|
36
|
+
* - {@link Worker.shutdown | `Worker.shutdown()`} was called.
|
|
37
|
+
* - The Activity was considered failed by the Server because any of the Activity timeouts have triggered (for example,
|
|
38
|
+
* the Server didn't receive a heartbeat within the {@link ActivityOptions.heartbeatTimeout}). The
|
|
39
|
+
* {@link CancelledFailure} will have `message: 'TIMED_OUT'`.
|
|
40
|
+
* - An Activity sends a heartbeat with `Context.current().heartbeat()` and the heartbeat details can't be converted by
|
|
41
|
+
* the Worker's configured {@link DataConverter}.
|
|
42
|
+
* - The Workflow Run reached a {@link https://docs.temporal.io/workflows#status | Closed state}, in which case the
|
|
43
|
+
* {@link CancelledFailure} will have `message: 'NOT_FOUND'`.
|
|
44
|
+
*
|
|
45
|
+
* The reason for the Cancellation is available at {@link CancelledFailure.message} or
|
|
46
|
+
* {@link Context#cancellationSignal | Context.cancellationSignal.reason}.
|
|
47
|
+
*
|
|
48
|
+
* There are two ways to handle Activity Cancellation:
|
|
20
49
|
*
|
|
21
|
-
* There are two ways to handle Activity cancellation:
|
|
22
50
|
* 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
|
|
23
|
-
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a
|
|
24
|
-
* {@link CancelledFailure}.
|
|
51
|
+
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
|
|
25
52
|
* 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
|
|
26
|
-
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that
|
|
27
|
-
* supports it.
|
|
53
|
+
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
|
|
28
54
|
*
|
|
29
55
|
* ### Examples
|
|
30
56
|
*
|
|
31
|
-
* #### An Activity that sends progress heartbeats and can be
|
|
57
|
+
* #### An Activity that sends progress heartbeats and can be Cancelled
|
|
32
58
|
*
|
|
33
59
|
* <!--SNIPSTART typescript-activity-fake-progress-->
|
|
34
60
|
* <!--SNIPEND-->
|
|
@@ -57,7 +83,7 @@ Object.defineProperty(exports, "errorCode", { enumerable: true, get: function ()
|
|
|
57
83
|
* Throw this error from an Activity in order to make the Worker forget about this Activity.
|
|
58
84
|
*
|
|
59
85
|
* The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
|
|
60
|
-
* {@link
|
|
86
|
+
* {@link Client.activity}.
|
|
61
87
|
*
|
|
62
88
|
* @example
|
|
63
89
|
*
|
|
@@ -112,7 +138,9 @@ class Context {
|
|
|
112
138
|
* attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
|
|
113
139
|
* {@link TimeoutFailure.lastHeartbeatDetails}.
|
|
114
140
|
*
|
|
115
|
-
*
|
|
141
|
+
* Calling `heartbeat()` from a Local Activity has no effect.
|
|
142
|
+
*
|
|
143
|
+
* Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
|
|
116
144
|
*/
|
|
117
145
|
heartbeat(details) {
|
|
118
146
|
this.heartbeatFn(details);
|
|
@@ -131,7 +159,7 @@ class Context {
|
|
|
131
159
|
}
|
|
132
160
|
/**
|
|
133
161
|
* Helper function for sleeping in an Activity.
|
|
134
|
-
* @param ms Sleep duration:
|
|
162
|
+
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
135
163
|
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
|
|
136
164
|
*/
|
|
137
165
|
sleep(ms) {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;;;AAEH,mFAAkE;AAElE,6CAAgD;AAChD,6CAA0E;AAAjE,0GAAA,gBAAgB,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAC7C,iFAM8C;AAF5C,wHAAA,YAAY,OAAA;AACZ,qHAAA,SAAS,OAAA;AAGX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAG3C;QACE,KAAK,EAAE,CAAC;QAHM,SAAI,GAAW,oBAAoB,CAAC;IAIpD,CAAC;CACF;AAND,gDAMC;AAED,cAAc;AACD,QAAA,iBAAiB,GAAG,IAAI,+BAAiB,EAAW,CAAC;AA8ElE;;;;;;;;;GASG;AACH,MAAa,OAAO;IA8BlB;;;;OAIG;IACH,YACE,IAAU,EACV,SAAyB,EACzB,kBAA+B,EAC/B,SAAkC;QAElC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACI,SAAS,CAAC,OAAiB;QAChC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO;QACnB,MAAM,KAAK,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;QAC3C,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,EAAmB;QAC9B,IAAI,MAAsB,CAAC;QAC3B,MAAM,KAAK,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAC1C,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,IAAA,qCAAU,EAAC,EAAE,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACnF,CAAC;CACF;AA3FD,0BA2FC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/activity",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Temporal.io SDK Activity sub-package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@temporalio/common": "^1.0
|
|
17
|
-
"@temporalio/internal-workflow-common": "^1.0
|
|
16
|
+
"@temporalio/common": "^1.3.0",
|
|
17
|
+
"@temporalio/internal-workflow-common": "^1.3.0",
|
|
18
18
|
"abort-controller": "^3.0.0"
|
|
19
19
|
},
|
|
20
20
|
"bugs": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"src",
|
|
29
29
|
"lib"
|
|
30
30
|
],
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "966d51d3545a5e84102190f5b762160b9dfe99c2"
|
|
32
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,19 +15,45 @@
|
|
|
15
15
|
*
|
|
16
16
|
* ### Cancellation
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* Activity Cancellation:
|
|
19
|
+
*
|
|
20
|
+
* - lets the Activity know it doesn't need to keep doing work, and
|
|
21
|
+
* - gives the Activity time to clean up any resources it has created.
|
|
22
|
+
*
|
|
23
|
+
* Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
|
|
24
|
+
* (which can't heartbeat but receive Cancellation anyway).
|
|
25
|
+
*
|
|
26
|
+
* An Activity may receive Cancellation if:
|
|
27
|
+
*
|
|
28
|
+
* - The Workflow scope containing the Activity call was requested to be Cancelled and
|
|
29
|
+
* {@link ActivityOptions.cancellationType} was **not** set to {@link ActivityCancellationType.ABANDON}. The scope can
|
|
30
|
+
* be cancelled in either of the following ways:
|
|
31
|
+
* - The entire Workflow was Cancelled (via {@link WorkflowHandle.cancel}).
|
|
32
|
+
* - Calling {@link CancellationScope.cancel}) from inside a Workflow.
|
|
33
|
+
* - The Worker has started to shut down. Shutdown is initiated by either:
|
|
34
|
+
* - One of the {@link RuntimeOptions.shutdownSignals} was sent to the process.
|
|
35
|
+
* - {@link Worker.shutdown | `Worker.shutdown()`} was called.
|
|
36
|
+
* - The Activity was considered failed by the Server because any of the Activity timeouts have triggered (for example,
|
|
37
|
+
* the Server didn't receive a heartbeat within the {@link ActivityOptions.heartbeatTimeout}). The
|
|
38
|
+
* {@link CancelledFailure} will have `message: 'TIMED_OUT'`.
|
|
39
|
+
* - An Activity sends a heartbeat with `Context.current().heartbeat()` and the heartbeat details can't be converted by
|
|
40
|
+
* the Worker's configured {@link DataConverter}.
|
|
41
|
+
* - The Workflow Run reached a {@link https://docs.temporal.io/workflows#status | Closed state}, in which case the
|
|
42
|
+
* {@link CancelledFailure} will have `message: 'NOT_FOUND'`.
|
|
43
|
+
*
|
|
44
|
+
* The reason for the Cancellation is available at {@link CancelledFailure.message} or
|
|
45
|
+
* {@link Context#cancellationSignal | Context.cancellationSignal.reason}.
|
|
46
|
+
*
|
|
47
|
+
* There are two ways to handle Activity Cancellation:
|
|
19
48
|
*
|
|
20
|
-
* There are two ways to handle Activity cancellation:
|
|
21
49
|
* 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
|
|
22
|
-
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a
|
|
23
|
-
* {@link CancelledFailure}.
|
|
50
|
+
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
|
|
24
51
|
* 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
|
|
25
|
-
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that
|
|
26
|
-
* supports it.
|
|
52
|
+
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
|
|
27
53
|
*
|
|
28
54
|
* ### Examples
|
|
29
55
|
*
|
|
30
|
-
* #### An Activity that sends progress heartbeats and can be
|
|
56
|
+
* #### An Activity that sends progress heartbeats and can be Cancelled
|
|
31
57
|
*
|
|
32
58
|
* <!--SNIPSTART typescript-activity-fake-progress-->
|
|
33
59
|
* <!--SNIPEND-->
|
|
@@ -59,7 +85,7 @@ export {
|
|
|
59
85
|
* Throw this error from an Activity in order to make the Worker forget about this Activity.
|
|
60
86
|
*
|
|
61
87
|
* The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
|
|
62
|
-
* {@link
|
|
88
|
+
* {@link Client.activity}.
|
|
63
89
|
*
|
|
64
90
|
* @example
|
|
65
91
|
*
|
|
@@ -145,13 +171,16 @@ export interface Info {
|
|
|
145
171
|
*/
|
|
146
172
|
heartbeatTimeoutMs?: number;
|
|
147
173
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
174
|
+
* The {@link Context.heartbeat | details} from the last recorded heartbeat from the last attempt of this Activity.
|
|
175
|
+
*
|
|
176
|
+
* Use this to resume your Activity from a checkpoint.
|
|
150
177
|
*/
|
|
151
178
|
heartbeatDetails: any;
|
|
152
179
|
|
|
153
180
|
/**
|
|
154
|
-
* Task
|
|
181
|
+
* Task Queue the Activity is scheduled in.
|
|
182
|
+
*
|
|
183
|
+
* For Local Activities, this is set to the Workflow's Task Queue.
|
|
155
184
|
*/
|
|
156
185
|
taskQueue: string;
|
|
157
186
|
}
|
|
@@ -224,7 +253,9 @@ export class Context {
|
|
|
224
253
|
* attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
|
|
225
254
|
* {@link TimeoutFailure.lastHeartbeatDetails}.
|
|
226
255
|
*
|
|
227
|
-
*
|
|
256
|
+
* Calling `heartbeat()` from a Local Activity has no effect.
|
|
257
|
+
*
|
|
258
|
+
* Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
|
|
228
259
|
*/
|
|
229
260
|
public heartbeat(details?: unknown): void {
|
|
230
261
|
this.heartbeatFn(details);
|
|
@@ -245,7 +276,7 @@ export class Context {
|
|
|
245
276
|
|
|
246
277
|
/**
|
|
247
278
|
* Helper function for sleeping in an Activity.
|
|
248
|
-
* @param ms Sleep duration:
|
|
279
|
+
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
249
280
|
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
|
|
250
281
|
*/
|
|
251
282
|
public sleep(ms: number | string): Promise<void> {
|