@temporalio/activity 1.1.0 → 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 CHANGED
@@ -15,15 +15,37 @@
15
15
  *
16
16
  * ### Cancellation
17
17
  *
18
- * Activity Cancellation serves three purposes:
18
+ * Activity Cancellation:
19
19
  *
20
- * - It lets an Activity know it doesn't need to keep doing work.
21
- * - It gives the Activity time to clean up any resources it has created.
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
22
  *
23
- * Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
23
+ * Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
24
24
  * (which can't heartbeat but receive Cancellation anyway).
25
25
  *
26
- * There are two ways to handle Activity cancellation:
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:
48
+ *
27
49
  * 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
28
50
  * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
29
51
  * 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
@@ -31,7 +53,7 @@
31
53
  *
32
54
  * ### Examples
33
55
  *
34
- * #### An Activity that sends progress heartbeats and can be cancelled
56
+ * #### An Activity that sends progress heartbeats and can be Cancelled
35
57
  *
36
58
  * <!--SNIPSTART typescript-activity-fake-progress-->
37
59
  * <!--SNIPEND-->
@@ -56,7 +78,7 @@ UntypedActivities, errorMessage, errorCode, } from '@temporalio/internal-workflo
56
78
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
57
79
  *
58
80
  * The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
59
- * {@link AsyncCompletionClient}.
81
+ * {@link Client.activity}.
60
82
  *
61
83
  * @example
62
84
  *
@@ -218,7 +240,7 @@ export declare class Context {
218
240
  static current(): Context;
219
241
  /**
220
242
  * Helper function for sleeping in an Activity.
221
- * @param ms Sleep duration: an {@link https://www.npmjs.com/package/ms | ms}-formatted string or number of milliseconds
243
+ * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
222
244
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
223
245
  */
224
246
  sleep(ms: number | string): Promise<void>;
package/lib/index.js CHANGED
@@ -16,15 +16,37 @@
16
16
  *
17
17
  * ### Cancellation
18
18
  *
19
- * Activity Cancellation serves three purposes:
19
+ * Activity Cancellation:
20
20
  *
21
- * - It lets an Activity know it doesn't need to keep doing work.
22
- * - It gives the Activity time to clean up any resources it has created.
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
23
  *
24
- * Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
24
+ * Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
25
25
  * (which can't heartbeat but receive Cancellation anyway).
26
26
  *
27
- * There are two ways to handle Activity cancellation:
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:
49
+ *
28
50
  * 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
29
51
  * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
30
52
  * 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
@@ -32,7 +54,7 @@
32
54
  *
33
55
  * ### Examples
34
56
  *
35
- * #### An Activity that sends progress heartbeats and can be cancelled
57
+ * #### An Activity that sends progress heartbeats and can be Cancelled
36
58
  *
37
59
  * <!--SNIPSTART typescript-activity-fake-progress-->
38
60
  * <!--SNIPEND-->
@@ -61,7 +83,7 @@ Object.defineProperty(exports, "errorCode", { enumerable: true, get: function ()
61
83
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
62
84
  *
63
85
  * The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
64
- * {@link AsyncCompletionClient}.
86
+ * {@link Client.activity}.
65
87
  *
66
88
  * @example
67
89
  *
@@ -137,7 +159,7 @@ class Context {
137
159
  }
138
160
  /**
139
161
  * Helper function for sleeping in an Activity.
140
- * @param ms Sleep duration: an {@link https://www.npmjs.com/package/ms | ms}-formatted string or number of milliseconds
162
+ * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
141
163
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
142
164
  */
143
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;;;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;;;;;;;;;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AAC,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.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.1.0",
17
- "@temporalio/internal-workflow-common": "^1.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": "132f23a47a93fecf3f39836b31f08ea837b30320"
31
+ "gitHead": "966d51d3545a5e84102190f5b762160b9dfe99c2"
32
32
  }
package/src/index.ts CHANGED
@@ -15,15 +15,37 @@
15
15
  *
16
16
  * ### Cancellation
17
17
  *
18
- * Activity Cancellation serves three purposes:
18
+ * Activity Cancellation:
19
19
  *
20
- * - It lets an Activity know it doesn't need to keep doing work.
21
- * - It gives the Activity time to clean up any resources it has created.
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
22
  *
23
- * Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
23
+ * Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
24
24
  * (which can't heartbeat but receive Cancellation anyway).
25
25
  *
26
- * There are two ways to handle Activity cancellation:
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:
48
+ *
27
49
  * 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
28
50
  * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
29
51
  * 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
@@ -31,7 +53,7 @@
31
53
  *
32
54
  * ### Examples
33
55
  *
34
- * #### An Activity that sends progress heartbeats and can be cancelled
56
+ * #### An Activity that sends progress heartbeats and can be Cancelled
35
57
  *
36
58
  * <!--SNIPSTART typescript-activity-fake-progress-->
37
59
  * <!--SNIPEND-->
@@ -63,7 +85,7 @@ export {
63
85
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
64
86
  *
65
87
  * The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
66
- * {@link AsyncCompletionClient}.
88
+ * {@link Client.activity}.
67
89
  *
68
90
  * @example
69
91
  *
@@ -254,7 +276,7 @@ export class Context {
254
276
 
255
277
  /**
256
278
  * Helper function for sleeping in an Activity.
257
- * @param ms Sleep duration: an {@link https://www.npmjs.com/package/ms | ms}-formatted string or number of milliseconds
279
+ * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
258
280
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
259
281
  */
260
282
  public sleep(ms: number | string): Promise<void> {