@temporalio/activity 1.12.2 → 1.13.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 +120 -9
- package/lib/index.js +85 -15
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/index.ts +137 -75
package/lib/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
*
|
|
49
49
|
* 1. `await` on {@link Context.cancelled | `Context.current().cancelled`} or
|
|
50
50
|
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
|
|
51
|
-
*
|
|
51
|
+
* 2. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
|
|
52
52
|
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
|
|
53
53
|
*
|
|
54
54
|
* ### Examples
|
|
@@ -69,7 +69,9 @@
|
|
|
69
69
|
* @module
|
|
70
70
|
*/
|
|
71
71
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
72
|
-
import { Logger, Duration, MetricMeter, Priority } from '@temporalio/common';
|
|
72
|
+
import { Logger, Duration, MetricMeter, Priority, ActivityCancellationDetails } from '@temporalio/common';
|
|
73
|
+
import { ActivityCancellationDetailsHolder } from '@temporalio/common/lib/activity-cancellation-details';
|
|
74
|
+
import { Client } from '@temporalio/client';
|
|
73
75
|
export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
|
|
74
76
|
ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/common';
|
|
75
77
|
/**
|
|
@@ -195,12 +197,6 @@ export interface Info {
|
|
|
195
197
|
* Call `Context.current()` from Activity code in order to get the current Activity's Context.
|
|
196
198
|
*/
|
|
197
199
|
export declare class Context {
|
|
198
|
-
/**
|
|
199
|
-
* Gets the context of the current Activity.
|
|
200
|
-
*
|
|
201
|
-
* Uses {@link https://nodejs.org/docs/latest-v16.x/api/async_context.html#class-asynclocalstorage | AsyncLocalStorage} under the hood to make it accessible in nested callbacks and promises.
|
|
202
|
-
*/
|
|
203
|
-
static current(): Context;
|
|
204
200
|
/**
|
|
205
201
|
* Holds information about the current executing Activity.
|
|
206
202
|
*/
|
|
@@ -233,6 +229,10 @@ export declare class Context {
|
|
|
233
229
|
* The heartbeat implementation, injected via the constructor.
|
|
234
230
|
*/
|
|
235
231
|
protected readonly heartbeatFn: (details?: any) => void;
|
|
232
|
+
/**
|
|
233
|
+
* The Worker's client, passed down through Activity context.
|
|
234
|
+
*/
|
|
235
|
+
protected readonly _client: Client | undefined;
|
|
236
236
|
/**
|
|
237
237
|
* The logger for this Activity.
|
|
238
238
|
*
|
|
@@ -256,12 +256,85 @@ export declare class Context {
|
|
|
256
256
|
* intercepts the `getMetricTags()` method.
|
|
257
257
|
*/
|
|
258
258
|
readonly metricMeter: MetricMeter;
|
|
259
|
+
/**
|
|
260
|
+
* Holder object for activity cancellation details
|
|
261
|
+
*/
|
|
262
|
+
protected readonly _cancellationDetails: ActivityCancellationDetailsHolder;
|
|
263
|
+
/**
|
|
264
|
+
* Gets the context of the current Activity.
|
|
265
|
+
*
|
|
266
|
+
* Uses {@link https://nodejs.org/docs/latest-v16.x/api/async_context.html#class-asynclocalstorage | AsyncLocalStorage} under the hood to make it accessible in nested callbacks and promises.
|
|
267
|
+
*/
|
|
268
|
+
static current(): Context;
|
|
259
269
|
/**
|
|
260
270
|
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
261
271
|
*
|
|
262
272
|
* @ignore
|
|
263
273
|
*/
|
|
264
|
-
constructor(
|
|
274
|
+
constructor(
|
|
275
|
+
/**
|
|
276
|
+
* Holds information about the current executing Activity.
|
|
277
|
+
*/
|
|
278
|
+
info: Info,
|
|
279
|
+
/**
|
|
280
|
+
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
281
|
+
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
282
|
+
*
|
|
283
|
+
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
284
|
+
*
|
|
285
|
+
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
286
|
+
*/
|
|
287
|
+
cancelled: Promise<never>,
|
|
288
|
+
/**
|
|
289
|
+
* An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
|
|
290
|
+
* Activity cancellation.
|
|
291
|
+
*
|
|
292
|
+
* This can be passed in to libraries such as
|
|
293
|
+
* {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
|
|
294
|
+
* in-progress request and
|
|
295
|
+
* {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
|
|
296
|
+
* to abort a child process, as well as other built-in node modules and modules found on npm.
|
|
297
|
+
*
|
|
298
|
+
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
299
|
+
*
|
|
300
|
+
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
301
|
+
*/
|
|
302
|
+
cancellationSignal: AbortSignal,
|
|
303
|
+
/**
|
|
304
|
+
* The heartbeat implementation, injected via the constructor.
|
|
305
|
+
*/
|
|
306
|
+
heartbeatFn: (details?: any) => void,
|
|
307
|
+
/**
|
|
308
|
+
* The Worker's client, passed down through Activity context.
|
|
309
|
+
*/
|
|
310
|
+
_client: Client | undefined,
|
|
311
|
+
/**
|
|
312
|
+
* The logger for this Activity.
|
|
313
|
+
*
|
|
314
|
+
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
|
|
315
|
+
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
|
|
316
|
+
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
|
|
317
|
+
*
|
|
318
|
+
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
|
|
319
|
+
* `getLogAttributes()` method.
|
|
320
|
+
*
|
|
321
|
+
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
|
|
322
|
+
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
|
|
323
|
+
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
324
|
+
* {@link Runtime.logger} property instead.
|
|
325
|
+
*/
|
|
326
|
+
log: Logger,
|
|
327
|
+
/**
|
|
328
|
+
* Get the metric meter for this activity with activity-specific tags.
|
|
329
|
+
*
|
|
330
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
331
|
+
* intercepts the `getMetricTags()` method.
|
|
332
|
+
*/
|
|
333
|
+
metricMeter: MetricMeter,
|
|
334
|
+
/**
|
|
335
|
+
* Holder object for activity cancellation details
|
|
336
|
+
*/
|
|
337
|
+
_cancellationDetails: ActivityCancellationDetailsHolder);
|
|
265
338
|
/**
|
|
266
339
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
267
340
|
*
|
|
@@ -284,12 +357,30 @@ export declare class Context {
|
|
|
284
357
|
* subscribe to cancellation notifications.
|
|
285
358
|
*/
|
|
286
359
|
readonly heartbeat: (details?: unknown) => void;
|
|
360
|
+
/**
|
|
361
|
+
* A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
|
|
362
|
+
*
|
|
363
|
+
* May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
|
|
364
|
+
* that was created without a Client.
|
|
365
|
+
*
|
|
366
|
+
* @experimental Client support over `NativeConnection` is experimental. Error handling may be
|
|
367
|
+
* incomplete or different from what would be observed using a {@link Connection}
|
|
368
|
+
* instead. Client doesn't support cancellation through a Signal.
|
|
369
|
+
*/
|
|
370
|
+
get client(): Client;
|
|
287
371
|
/**
|
|
288
372
|
* Helper function for sleeping in an Activity.
|
|
289
373
|
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
290
374
|
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
|
|
291
375
|
*/
|
|
292
376
|
readonly sleep: (ms: Duration) => Promise<void>;
|
|
377
|
+
/**
|
|
378
|
+
* Return the cancellation details for this activity, if any.
|
|
379
|
+
* @returns an object with boolean properties that describes the reason for cancellation, or undefined if not cancelled.
|
|
380
|
+
*
|
|
381
|
+
* @experimental Activity cancellation details include usage of experimental features such as activity pause, and may be subject to change.
|
|
382
|
+
*/
|
|
383
|
+
get cancellationDetails(): ActivityCancellationDetails | undefined;
|
|
293
384
|
}
|
|
294
385
|
/**
|
|
295
386
|
* The current Activity's context.
|
|
@@ -334,6 +425,13 @@ export declare function heartbeat(details?: unknown): void;
|
|
|
334
425
|
* This is a shortcut for `Context.current().cancelled` (see {@link Context.cancelled}).
|
|
335
426
|
*/
|
|
336
427
|
export declare function cancelled(): Promise<never>;
|
|
428
|
+
/**
|
|
429
|
+
* Return the cancellation details for this activity, if any.
|
|
430
|
+
* @returns an object with boolean properties that describes the reason for cancellation, or undefined if not cancelled.
|
|
431
|
+
*
|
|
432
|
+
* @experimental Activity cancellation details include usage of experimental features such as activity pause, and may be subject to change.
|
|
433
|
+
*/
|
|
434
|
+
export declare function cancellationDetails(): ActivityCancellationDetails | undefined;
|
|
337
435
|
/**
|
|
338
436
|
* Return an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to
|
|
339
437
|
* react to Activity cancellation.
|
|
@@ -349,6 +447,19 @@ export declare function cancelled(): Promise<never>;
|
|
|
349
447
|
* This is a shortcut for `Context.current().cancellationSignal` (see {@link Context.cancellationSignal}).
|
|
350
448
|
*/
|
|
351
449
|
export declare function cancellationSignal(): AbortSignal;
|
|
450
|
+
/**
|
|
451
|
+
* A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
|
|
452
|
+
*
|
|
453
|
+
* May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
|
|
454
|
+
* that was created without a Client.
|
|
455
|
+
*
|
|
456
|
+
* This is a shortcut for `Context.current().client` (see {@link Context.client}).
|
|
457
|
+
*
|
|
458
|
+
* @experimental Client support over `NativeConnection` is experimental. Error handling may be
|
|
459
|
+
* incomplete or different from what would be observed using a {@link Connection}
|
|
460
|
+
* instead. Client doesn't support cancellation through a Signal.
|
|
461
|
+
*/
|
|
462
|
+
export declare function getClient(): Client;
|
|
352
463
|
/**
|
|
353
464
|
* Get the metric meter for the current activity, with activity-specific tags.
|
|
354
465
|
*
|
package/lib/index.js
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
*
|
|
50
50
|
* 1. `await` on {@link Context.cancelled | `Context.current().cancelled`} or
|
|
51
51
|
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
|
|
52
|
-
*
|
|
52
|
+
* 2. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
|
|
53
53
|
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
|
|
54
54
|
*
|
|
55
55
|
* ### Examples
|
|
@@ -81,13 +81,16 @@ exports.activityInfo = activityInfo;
|
|
|
81
81
|
exports.sleep = sleep;
|
|
82
82
|
exports.heartbeat = heartbeat;
|
|
83
83
|
exports.cancelled = cancelled;
|
|
84
|
+
exports.cancellationDetails = cancellationDetails;
|
|
84
85
|
exports.cancellationSignal = cancellationSignal;
|
|
86
|
+
exports.getClient = getClient;
|
|
85
87
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
88
|
+
const common_1 = require("@temporalio/common");
|
|
86
89
|
const time_1 = require("@temporalio/common/lib/time");
|
|
87
90
|
const type_helpers_1 = require("@temporalio/common/lib/type-helpers");
|
|
88
|
-
var
|
|
89
|
-
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return
|
|
90
|
-
Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return
|
|
91
|
+
var common_2 = require("@temporalio/common");
|
|
92
|
+
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_2.ApplicationFailure; } });
|
|
93
|
+
Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_2.CancelledFailure; } });
|
|
91
94
|
/**
|
|
92
95
|
* Throw this error from an Activity in order to make the Worker forget about this Activity.
|
|
93
96
|
*
|
|
@@ -128,6 +131,14 @@ exports.asyncLocalStorage = globalThis[asyncLocalStorageSymbol];
|
|
|
128
131
|
* Call `Context.current()` from Activity code in order to get the current Activity's Context.
|
|
129
132
|
*/
|
|
130
133
|
class Context {
|
|
134
|
+
info;
|
|
135
|
+
cancelled;
|
|
136
|
+
cancellationSignal;
|
|
137
|
+
heartbeatFn;
|
|
138
|
+
_client;
|
|
139
|
+
log;
|
|
140
|
+
metricMeter;
|
|
141
|
+
_cancellationDetails;
|
|
131
142
|
/**
|
|
132
143
|
* Gets the context of the current Activity.
|
|
133
144
|
*
|
|
@@ -140,10 +151,16 @@ class Context {
|
|
|
140
151
|
}
|
|
141
152
|
return store;
|
|
142
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
156
|
+
*
|
|
157
|
+
* @ignore
|
|
158
|
+
*/
|
|
159
|
+
constructor(
|
|
143
160
|
/**
|
|
144
161
|
* Holds information about the current executing Activity.
|
|
145
162
|
*/
|
|
146
|
-
info
|
|
163
|
+
info,
|
|
147
164
|
/**
|
|
148
165
|
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
149
166
|
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
@@ -152,7 +169,7 @@ class Context {
|
|
|
152
169
|
*
|
|
153
170
|
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
154
171
|
*/
|
|
155
|
-
cancelled
|
|
172
|
+
cancelled,
|
|
156
173
|
/**
|
|
157
174
|
* An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
|
|
158
175
|
* Activity cancellation.
|
|
@@ -167,11 +184,15 @@ class Context {
|
|
|
167
184
|
*
|
|
168
185
|
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
169
186
|
*/
|
|
170
|
-
cancellationSignal
|
|
187
|
+
cancellationSignal,
|
|
171
188
|
/**
|
|
172
189
|
* The heartbeat implementation, injected via the constructor.
|
|
173
190
|
*/
|
|
174
|
-
heartbeatFn
|
|
191
|
+
heartbeatFn,
|
|
192
|
+
/**
|
|
193
|
+
* The Worker's client, passed down through Activity context.
|
|
194
|
+
*/
|
|
195
|
+
_client,
|
|
175
196
|
/**
|
|
176
197
|
* The logger for this Activity.
|
|
177
198
|
*
|
|
@@ -187,26 +208,26 @@ class Context {
|
|
|
187
208
|
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
188
209
|
* {@link Runtime.logger} property instead.
|
|
189
210
|
*/
|
|
190
|
-
log
|
|
211
|
+
log,
|
|
191
212
|
/**
|
|
192
213
|
* Get the metric meter for this activity with activity-specific tags.
|
|
193
214
|
*
|
|
194
215
|
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
195
216
|
* intercepts the `getMetricTags()` method.
|
|
196
217
|
*/
|
|
197
|
-
metricMeter
|
|
218
|
+
metricMeter,
|
|
198
219
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* @ignore
|
|
220
|
+
* Holder object for activity cancellation details
|
|
202
221
|
*/
|
|
203
|
-
|
|
222
|
+
_cancellationDetails) {
|
|
204
223
|
this.info = info;
|
|
205
224
|
this.cancelled = cancelled;
|
|
206
225
|
this.cancellationSignal = cancellationSignal;
|
|
207
|
-
this.heartbeatFn =
|
|
226
|
+
this.heartbeatFn = heartbeatFn;
|
|
227
|
+
this._client = _client;
|
|
208
228
|
this.log = log;
|
|
209
229
|
this.metricMeter = metricMeter;
|
|
230
|
+
this._cancellationDetails = _cancellationDetails;
|
|
210
231
|
}
|
|
211
232
|
/**
|
|
212
233
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
@@ -232,6 +253,22 @@ class Context {
|
|
|
232
253
|
heartbeat = (details) => {
|
|
233
254
|
this.heartbeatFn(details);
|
|
234
255
|
};
|
|
256
|
+
/**
|
|
257
|
+
* A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
|
|
258
|
+
*
|
|
259
|
+
* May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
|
|
260
|
+
* that was created without a Client.
|
|
261
|
+
*
|
|
262
|
+
* @experimental Client support over `NativeConnection` is experimental. Error handling may be
|
|
263
|
+
* incomplete or different from what would be observed using a {@link Connection}
|
|
264
|
+
* instead. Client doesn't support cancellation through a Signal.
|
|
265
|
+
*/
|
|
266
|
+
get client() {
|
|
267
|
+
if (this._client === undefined) {
|
|
268
|
+
throw new common_1.IllegalStateError('No Client available. This may be a MockActivityEnvironment that was created without a Client.');
|
|
269
|
+
}
|
|
270
|
+
return this._client;
|
|
271
|
+
}
|
|
235
272
|
/**
|
|
236
273
|
* Helper function for sleeping in an Activity.
|
|
237
274
|
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
@@ -244,6 +281,15 @@ class Context {
|
|
|
244
281
|
});
|
|
245
282
|
return Promise.race([this.cancelled.finally(() => clearTimeout(handle)), timer]);
|
|
246
283
|
};
|
|
284
|
+
/**
|
|
285
|
+
* Return the cancellation details for this activity, if any.
|
|
286
|
+
* @returns an object with boolean properties that describes the reason for cancellation, or undefined if not cancelled.
|
|
287
|
+
*
|
|
288
|
+
* @experimental Activity cancellation details include usage of experimental features such as activity pause, and may be subject to change.
|
|
289
|
+
*/
|
|
290
|
+
get cancellationDetails() {
|
|
291
|
+
return this._cancellationDetails.details;
|
|
292
|
+
}
|
|
247
293
|
}
|
|
248
294
|
exports.Context = Context;
|
|
249
295
|
/**
|
|
@@ -319,6 +365,15 @@ function heartbeat(details) {
|
|
|
319
365
|
function cancelled() {
|
|
320
366
|
return Context.current().cancelled;
|
|
321
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Return the cancellation details for this activity, if any.
|
|
370
|
+
* @returns an object with boolean properties that describes the reason for cancellation, or undefined if not cancelled.
|
|
371
|
+
*
|
|
372
|
+
* @experimental Activity cancellation details include usage of experimental features such as activity pause, and may be subject to change.
|
|
373
|
+
*/
|
|
374
|
+
function cancellationDetails() {
|
|
375
|
+
return Context.current().cancellationDetails;
|
|
376
|
+
}
|
|
322
377
|
/**
|
|
323
378
|
* Return an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to
|
|
324
379
|
* react to Activity cancellation.
|
|
@@ -336,6 +391,21 @@ function cancelled() {
|
|
|
336
391
|
function cancellationSignal() {
|
|
337
392
|
return Context.current().cancellationSignal;
|
|
338
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
|
|
396
|
+
*
|
|
397
|
+
* May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
|
|
398
|
+
* that was created without a Client.
|
|
399
|
+
*
|
|
400
|
+
* This is a shortcut for `Context.current().client` (see {@link Context.client}).
|
|
401
|
+
*
|
|
402
|
+
* @experimental Client support over `NativeConnection` is experimental. Error handling may be
|
|
403
|
+
* incomplete or different from what would be observed using a {@link Connection}
|
|
404
|
+
* instead. Client doesn't support cancellation through a Signal.
|
|
405
|
+
*/
|
|
406
|
+
function getClient() {
|
|
407
|
+
return Context.current().client;
|
|
408
|
+
}
|
|
339
409
|
/**
|
|
340
410
|
* Get the metric meter for the current activity, with activity-specific tags.
|
|
341
411
|
*
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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IACD,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW;QACpD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACvF,CAAC;IACD,QAAQ,CAAC,IAAI;QACX,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/activity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Temporal.io SDK Activity sub-package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@temporalio/
|
|
16
|
+
"@temporalio/client": "1.13.0",
|
|
17
|
+
"@temporalio/common": "1.13.0",
|
|
17
18
|
"abort-controller": "^3.0.0"
|
|
18
19
|
},
|
|
19
20
|
"engines": {
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"src",
|
|
36
37
|
"lib"
|
|
37
38
|
],
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "cf7c1e7d70f0c775f1382fd335b8bd721495f8cc"
|
|
39
40
|
}
|
package/src/index.ts
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
*
|
|
49
49
|
* 1. `await` on {@link Context.cancelled | `Context.current().cancelled`} or
|
|
50
50
|
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
|
|
51
|
-
*
|
|
51
|
+
* 2. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
|
|
52
52
|
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
|
|
53
53
|
*
|
|
54
54
|
* ### Examples
|
|
@@ -70,9 +70,20 @@
|
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
73
|
-
import {
|
|
73
|
+
import {
|
|
74
|
+
Logger,
|
|
75
|
+
Duration,
|
|
76
|
+
LogLevel,
|
|
77
|
+
LogMetadata,
|
|
78
|
+
MetricMeter,
|
|
79
|
+
Priority,
|
|
80
|
+
ActivityCancellationDetails,
|
|
81
|
+
IllegalStateError,
|
|
82
|
+
} from '@temporalio/common';
|
|
74
83
|
import { msToNumber } from '@temporalio/common/lib/time';
|
|
75
84
|
import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
|
|
85
|
+
import { ActivityCancellationDetailsHolder } from '@temporalio/common/lib/activity-cancellation-details';
|
|
86
|
+
import { Client } from '@temporalio/client';
|
|
76
87
|
|
|
77
88
|
export {
|
|
78
89
|
ActivityFunction,
|
|
@@ -229,86 +240,82 @@ export class Context {
|
|
|
229
240
|
}
|
|
230
241
|
|
|
231
242
|
/**
|
|
232
|
-
*
|
|
233
|
-
*/
|
|
234
|
-
public readonly info: Info;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
238
|
-
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
239
|
-
*
|
|
240
|
-
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
243
|
+
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
241
244
|
*
|
|
242
|
-
* @
|
|
245
|
+
* @ignore
|
|
243
246
|
*/
|
|
244
|
-
|
|
247
|
+
constructor(
|
|
248
|
+
/**
|
|
249
|
+
* Holds information about the current executing Activity.
|
|
250
|
+
*/
|
|
251
|
+
public readonly info: Info,
|
|
245
252
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
*
|
|
256
|
-
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
257
|
-
*
|
|
258
|
-
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
259
|
-
*/
|
|
260
|
-
public readonly cancellationSignal: AbortSignal;
|
|
253
|
+
/**
|
|
254
|
+
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
255
|
+
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
256
|
+
*
|
|
257
|
+
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
258
|
+
*
|
|
259
|
+
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
260
|
+
*/
|
|
261
|
+
public readonly cancelled: Promise<never>,
|
|
261
262
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
263
|
+
/**
|
|
264
|
+
* An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
|
|
265
|
+
* Activity cancellation.
|
|
266
|
+
*
|
|
267
|
+
* This can be passed in to libraries such as
|
|
268
|
+
* {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
|
|
269
|
+
* in-progress request and
|
|
270
|
+
* {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
|
|
271
|
+
* to abort a child process, as well as other built-in node modules and modules found on npm.
|
|
272
|
+
*
|
|
273
|
+
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
274
|
+
*
|
|
275
|
+
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
276
|
+
*/
|
|
277
|
+
public readonly cancellationSignal: AbortSignal,
|
|
266
278
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
|
|
272
|
-
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
|
|
273
|
-
*
|
|
274
|
-
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
|
|
275
|
-
* `getLogAttributes()` method.
|
|
276
|
-
*
|
|
277
|
-
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
|
|
278
|
-
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
|
|
279
|
-
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
280
|
-
* {@link Runtime.logger} property instead.
|
|
281
|
-
*/
|
|
282
|
-
public log: Logger;
|
|
279
|
+
/**
|
|
280
|
+
* The heartbeat implementation, injected via the constructor.
|
|
281
|
+
*/
|
|
282
|
+
protected readonly heartbeatFn: (details?: any) => void,
|
|
283
283
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
* intercepts the `getMetricTags()` method.
|
|
289
|
-
*/
|
|
290
|
-
public readonly metricMeter: MetricMeter;
|
|
284
|
+
/**
|
|
285
|
+
* The Worker's client, passed down through Activity context.
|
|
286
|
+
*/
|
|
287
|
+
protected readonly _client: Client | undefined,
|
|
291
288
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
289
|
+
/**
|
|
290
|
+
* The logger for this Activity.
|
|
291
|
+
*
|
|
292
|
+
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
|
|
293
|
+
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
|
|
294
|
+
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
|
|
295
|
+
*
|
|
296
|
+
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
|
|
297
|
+
* `getLogAttributes()` method.
|
|
298
|
+
*
|
|
299
|
+
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
|
|
300
|
+
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
|
|
301
|
+
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
302
|
+
* {@link Runtime.logger} property instead.
|
|
303
|
+
*/
|
|
304
|
+
public log: Logger,
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get the metric meter for this activity with activity-specific tags.
|
|
308
|
+
*
|
|
309
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
310
|
+
* intercepts the `getMetricTags()` method.
|
|
311
|
+
*/
|
|
312
|
+
public readonly metricMeter: MetricMeter,
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Holder object for activity cancellation details
|
|
316
|
+
*/
|
|
317
|
+
protected readonly _cancellationDetails: ActivityCancellationDetailsHolder
|
|
318
|
+
) {}
|
|
312
319
|
|
|
313
320
|
/**
|
|
314
321
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
@@ -335,6 +342,25 @@ export class Context {
|
|
|
335
342
|
this.heartbeatFn(details);
|
|
336
343
|
};
|
|
337
344
|
|
|
345
|
+
/**
|
|
346
|
+
* A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
|
|
347
|
+
*
|
|
348
|
+
* May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
|
|
349
|
+
* that was created without a Client.
|
|
350
|
+
*
|
|
351
|
+
* @experimental Client support over `NativeConnection` is experimental. Error handling may be
|
|
352
|
+
* incomplete or different from what would be observed using a {@link Connection}
|
|
353
|
+
* instead. Client doesn't support cancellation through a Signal.
|
|
354
|
+
*/
|
|
355
|
+
public get client(): Client {
|
|
356
|
+
if (this._client === undefined) {
|
|
357
|
+
throw new IllegalStateError(
|
|
358
|
+
'No Client available. This may be a MockActivityEnvironment that was created without a Client.'
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
return this._client;
|
|
362
|
+
}
|
|
363
|
+
|
|
338
364
|
/**
|
|
339
365
|
* Helper function for sleeping in an Activity.
|
|
340
366
|
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
@@ -347,6 +373,16 @@ export class Context {
|
|
|
347
373
|
});
|
|
348
374
|
return Promise.race([this.cancelled.finally(() => clearTimeout(handle)), timer]);
|
|
349
375
|
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Return the cancellation details for this activity, if any.
|
|
379
|
+
* @returns an object with boolean properties that describes the reason for cancellation, or undefined if not cancelled.
|
|
380
|
+
*
|
|
381
|
+
* @experimental Activity cancellation details include usage of experimental features such as activity pause, and may be subject to change.
|
|
382
|
+
*/
|
|
383
|
+
public get cancellationDetails(): ActivityCancellationDetails | undefined {
|
|
384
|
+
return this._cancellationDetails.details;
|
|
385
|
+
}
|
|
350
386
|
}
|
|
351
387
|
|
|
352
388
|
/**
|
|
@@ -427,6 +463,16 @@ export function cancelled(): Promise<never> {
|
|
|
427
463
|
return Context.current().cancelled;
|
|
428
464
|
}
|
|
429
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Return the cancellation details for this activity, if any.
|
|
468
|
+
* @returns an object with boolean properties that describes the reason for cancellation, or undefined if not cancelled.
|
|
469
|
+
*
|
|
470
|
+
* @experimental Activity cancellation details include usage of experimental features such as activity pause, and may be subject to change.
|
|
471
|
+
*/
|
|
472
|
+
export function cancellationDetails(): ActivityCancellationDetails | undefined {
|
|
473
|
+
return Context.current().cancellationDetails;
|
|
474
|
+
}
|
|
475
|
+
|
|
430
476
|
/**
|
|
431
477
|
* Return an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to
|
|
432
478
|
* react to Activity cancellation.
|
|
@@ -445,6 +491,22 @@ export function cancellationSignal(): AbortSignal {
|
|
|
445
491
|
return Context.current().cancellationSignal;
|
|
446
492
|
}
|
|
447
493
|
|
|
494
|
+
/**
|
|
495
|
+
* A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
|
|
496
|
+
*
|
|
497
|
+
* May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
|
|
498
|
+
* that was created without a Client.
|
|
499
|
+
*
|
|
500
|
+
* This is a shortcut for `Context.current().client` (see {@link Context.client}).
|
|
501
|
+
*
|
|
502
|
+
* @experimental Client support over `NativeConnection` is experimental. Error handling may be
|
|
503
|
+
* incomplete or different from what would be observed using a {@link Connection}
|
|
504
|
+
* instead. Client doesn't support cancellation through a Signal.
|
|
505
|
+
*/
|
|
506
|
+
export function getClient(): Client {
|
|
507
|
+
return Context.current().client;
|
|
508
|
+
}
|
|
509
|
+
|
|
448
510
|
/**
|
|
449
511
|
* Get the metric meter for the current activity, with activity-specific tags.
|
|
450
512
|
*
|