@temporalio/activity 1.1.0 → 1.4.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-->
@@ -49,14 +71,13 @@
49
71
  /// <reference types="node" />
50
72
  import { AbortSignal } from 'abort-controller';
51
73
  import { AsyncLocalStorage } from 'async_hooks';
52
- export { CancelledFailure, ApplicationFailure } from '@temporalio/common';
53
74
  export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
54
- UntypedActivities, errorMessage, errorCode, } from '@temporalio/internal-workflow-common';
75
+ ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/common';
55
76
  /**
56
77
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
57
78
  *
58
79
  * The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
59
- * {@link AsyncCompletionClient}.
80
+ * {@link Client.activity}.
60
81
  *
61
82
  * @example
62
83
  *
@@ -218,7 +239,7 @@ export declare class Context {
218
239
  static current(): Context;
219
240
  /**
220
241
  * 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
242
+ * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
222
243
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
223
244
  */
224
245
  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-->
@@ -48,20 +70,17 @@
48
70
  * @module
49
71
  */
50
72
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.errorCode = exports.errorMessage = exports.ApplicationFailure = exports.CancelledFailure = void 0;
52
- const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
73
+ exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.CancelledFailure = exports.ApplicationFailure = void 0;
53
74
  const async_hooks_1 = require("async_hooks");
75
+ const time_1 = require("@temporalio/common/lib/time");
54
76
  var common_1 = require("@temporalio/common");
55
- Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_1.CancelledFailure; } });
56
77
  Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_1.ApplicationFailure; } });
57
- var internal_workflow_common_2 = require("@temporalio/internal-workflow-common");
58
- Object.defineProperty(exports, "errorMessage", { enumerable: true, get: function () { return internal_workflow_common_2.errorMessage; } });
59
- Object.defineProperty(exports, "errorCode", { enumerable: true, get: function () { return internal_workflow_common_2.errorCode; } });
78
+ Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_1.CancelledFailure; } });
60
79
  /**
61
80
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
62
81
  *
63
82
  * The Activity can then be completed asynchronously (from anywhere—usually outside the Worker) using
64
- * {@link AsyncCompletionClient}.
83
+ * {@link Client.activity}.
65
84
  *
66
85
  * @example
67
86
  *
@@ -137,13 +156,13 @@ class Context {
137
156
  }
138
157
  /**
139
158
  * 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
159
+ * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
141
160
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
142
161
  */
143
162
  sleep(ms) {
144
163
  let handle;
145
164
  const timer = new Promise((resolve) => {
146
- handle = setTimeout(resolve, (0, internal_workflow_common_1.msToNumber)(ms));
165
+ handle = setTimeout(resolve, (0, time_1.msToNumber)(ms));
147
166
  });
148
167
  return Promise.race([this.cancelled.finally(() => clearTimeout(handle)), timer]);
149
168
  }
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;;;;;;;;;GASG;AACH,MAAa,OAAO;IA8BlB;;;;OAIG;IACH,YACE,IAAU,EACV,SAAyB,EACzB,kBAA+B,EAC/B,SAAkC;QAElC,I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AC;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.4.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,7 @@
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.4.0",
18
17
  "abort-controller": "^3.0.0"
19
18
  },
20
19
  "bugs": {
@@ -28,5 +27,5 @@
28
27
  "src",
29
28
  "lib"
30
29
  ],
31
- "gitHead": "132f23a47a93fecf3f39836b31f08ea837b30320"
30
+ "gitHead": "4b757ebbc052f327cc37e5693f46c8127c156b0c"
32
31
  }
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-->
@@ -47,23 +69,23 @@
47
69
  * @module
48
70
  */
49
71
 
50
- import { msToNumber } from '@temporalio/internal-workflow-common';
51
72
  import { AbortSignal } from 'abort-controller';
52
73
  import { AsyncLocalStorage } from 'async_hooks';
53
- export { CancelledFailure, ApplicationFailure } from '@temporalio/common';
74
+ import { msToNumber } from '@temporalio/common/lib/time';
75
+
54
76
  export {
55
77
  ActivityFunction,
56
78
  ActivityInterface, // eslint-disable-line deprecation/deprecation
79
+ ApplicationFailure,
80
+ CancelledFailure,
57
81
  UntypedActivities,
58
- errorMessage,
59
- errorCode,
60
- } from '@temporalio/internal-workflow-common';
82
+ } from '@temporalio/common';
61
83
 
62
84
  /**
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> {