@temporalio/activity 1.12.3 → 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 +100 -8
- package/lib/index.js +64 -18
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/index.ts +105 -79
package/lib/index.d.ts
CHANGED
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
72
72
|
import { Logger, Duration, MetricMeter, Priority, ActivityCancellationDetails } from '@temporalio/common';
|
|
73
73
|
import { ActivityCancellationDetailsHolder } from '@temporalio/common/lib/activity-cancellation-details';
|
|
74
|
+
import { Client } from '@temporalio/client';
|
|
74
75
|
export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
|
|
75
76
|
ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/common';
|
|
76
77
|
/**
|
|
@@ -196,12 +197,6 @@ export interface Info {
|
|
|
196
197
|
* Call `Context.current()` from Activity code in order to get the current Activity's Context.
|
|
197
198
|
*/
|
|
198
199
|
export declare class Context {
|
|
199
|
-
/**
|
|
200
|
-
* Gets the context of the current Activity.
|
|
201
|
-
*
|
|
202
|
-
* 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.
|
|
203
|
-
*/
|
|
204
|
-
static current(): Context;
|
|
205
200
|
/**
|
|
206
201
|
* Holds information about the current executing Activity.
|
|
207
202
|
*/
|
|
@@ -234,6 +229,10 @@ export declare class Context {
|
|
|
234
229
|
* The heartbeat implementation, injected via the constructor.
|
|
235
230
|
*/
|
|
236
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;
|
|
237
236
|
/**
|
|
238
237
|
* The logger for this Activity.
|
|
239
238
|
*
|
|
@@ -260,13 +259,82 @@ export declare class Context {
|
|
|
260
259
|
/**
|
|
261
260
|
* Holder object for activity cancellation details
|
|
262
261
|
*/
|
|
263
|
-
|
|
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;
|
|
264
269
|
/**
|
|
265
270
|
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
266
271
|
*
|
|
267
272
|
* @ignore
|
|
268
273
|
*/
|
|
269
|
-
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);
|
|
270
338
|
/**
|
|
271
339
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
272
340
|
*
|
|
@@ -289,6 +357,17 @@ export declare class Context {
|
|
|
289
357
|
* subscribe to cancellation notifications.
|
|
290
358
|
*/
|
|
291
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;
|
|
292
371
|
/**
|
|
293
372
|
* Helper function for sleeping in an Activity.
|
|
294
373
|
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
@@ -368,6 +447,19 @@ export declare function cancellationDetails(): ActivityCancellationDetails | und
|
|
|
368
447
|
* This is a shortcut for `Context.current().cancellationSignal` (see {@link Context.cancellationSignal}).
|
|
369
448
|
*/
|
|
370
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;
|
|
371
463
|
/**
|
|
372
464
|
* Get the metric meter for the current activity, with activity-specific tags.
|
|
373
465
|
*
|
package/lib/index.js
CHANGED
|
@@ -83,12 +83,14 @@ exports.heartbeat = heartbeat;
|
|
|
83
83
|
exports.cancelled = cancelled;
|
|
84
84
|
exports.cancellationDetails = cancellationDetails;
|
|
85
85
|
exports.cancellationSignal = cancellationSignal;
|
|
86
|
+
exports.getClient = getClient;
|
|
86
87
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
88
|
+
const common_1 = require("@temporalio/common");
|
|
87
89
|
const time_1 = require("@temporalio/common/lib/time");
|
|
88
90
|
const type_helpers_1 = require("@temporalio/common/lib/type-helpers");
|
|
89
|
-
var
|
|
90
|
-
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return
|
|
91
|
-
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; } });
|
|
92
94
|
/**
|
|
93
95
|
* Throw this error from an Activity in order to make the Worker forget about this Activity.
|
|
94
96
|
*
|
|
@@ -129,6 +131,14 @@ exports.asyncLocalStorage = globalThis[asyncLocalStorageSymbol];
|
|
|
129
131
|
* Call `Context.current()` from Activity code in order to get the current Activity's Context.
|
|
130
132
|
*/
|
|
131
133
|
class Context {
|
|
134
|
+
info;
|
|
135
|
+
cancelled;
|
|
136
|
+
cancellationSignal;
|
|
137
|
+
heartbeatFn;
|
|
138
|
+
_client;
|
|
139
|
+
log;
|
|
140
|
+
metricMeter;
|
|
141
|
+
_cancellationDetails;
|
|
132
142
|
/**
|
|
133
143
|
* Gets the context of the current Activity.
|
|
134
144
|
*
|
|
@@ -141,10 +151,16 @@ class Context {
|
|
|
141
151
|
}
|
|
142
152
|
return store;
|
|
143
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
156
|
+
*
|
|
157
|
+
* @ignore
|
|
158
|
+
*/
|
|
159
|
+
constructor(
|
|
144
160
|
/**
|
|
145
161
|
* Holds information about the current executing Activity.
|
|
146
162
|
*/
|
|
147
|
-
info
|
|
163
|
+
info,
|
|
148
164
|
/**
|
|
149
165
|
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
150
166
|
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
@@ -153,7 +169,7 @@ class Context {
|
|
|
153
169
|
*
|
|
154
170
|
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
155
171
|
*/
|
|
156
|
-
cancelled
|
|
172
|
+
cancelled,
|
|
157
173
|
/**
|
|
158
174
|
* An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
|
|
159
175
|
* Activity cancellation.
|
|
@@ -168,11 +184,15 @@ class Context {
|
|
|
168
184
|
*
|
|
169
185
|
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
170
186
|
*/
|
|
171
|
-
cancellationSignal
|
|
187
|
+
cancellationSignal,
|
|
172
188
|
/**
|
|
173
189
|
* The heartbeat implementation, injected via the constructor.
|
|
174
190
|
*/
|
|
175
|
-
heartbeatFn
|
|
191
|
+
heartbeatFn,
|
|
192
|
+
/**
|
|
193
|
+
* The Worker's client, passed down through Activity context.
|
|
194
|
+
*/
|
|
195
|
+
_client,
|
|
176
196
|
/**
|
|
177
197
|
* The logger for this Activity.
|
|
178
198
|
*
|
|
@@ -188,31 +208,26 @@ class Context {
|
|
|
188
208
|
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
189
209
|
* {@link Runtime.logger} property instead.
|
|
190
210
|
*/
|
|
191
|
-
log
|
|
211
|
+
log,
|
|
192
212
|
/**
|
|
193
213
|
* Get the metric meter for this activity with activity-specific tags.
|
|
194
214
|
*
|
|
195
215
|
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
196
216
|
* intercepts the `getMetricTags()` method.
|
|
197
217
|
*/
|
|
198
|
-
metricMeter
|
|
218
|
+
metricMeter,
|
|
199
219
|
/**
|
|
200
220
|
* Holder object for activity cancellation details
|
|
201
221
|
*/
|
|
202
|
-
_cancellationDetails
|
|
203
|
-
/**
|
|
204
|
-
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
205
|
-
*
|
|
206
|
-
* @ignore
|
|
207
|
-
*/
|
|
208
|
-
constructor(info, cancelled, cancellationSignal, heartbeat, log, metricMeter, details) {
|
|
222
|
+
_cancellationDetails) {
|
|
209
223
|
this.info = info;
|
|
210
224
|
this.cancelled = cancelled;
|
|
211
225
|
this.cancellationSignal = cancellationSignal;
|
|
212
|
-
this.heartbeatFn =
|
|
226
|
+
this.heartbeatFn = heartbeatFn;
|
|
227
|
+
this._client = _client;
|
|
213
228
|
this.log = log;
|
|
214
229
|
this.metricMeter = metricMeter;
|
|
215
|
-
this._cancellationDetails =
|
|
230
|
+
this._cancellationDetails = _cancellationDetails;
|
|
216
231
|
}
|
|
217
232
|
/**
|
|
218
233
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
@@ -238,6 +253,22 @@ class Context {
|
|
|
238
253
|
heartbeat = (details) => {
|
|
239
254
|
this.heartbeatFn(details);
|
|
240
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
|
+
}
|
|
241
272
|
/**
|
|
242
273
|
* Helper function for sleeping in an Activity.
|
|
243
274
|
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
@@ -360,6 +391,21 @@ function cancellationDetails() {
|
|
|
360
391
|
function cancellationSignal() {
|
|
361
392
|
return Context.current().cancellationSignal;
|
|
362
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
|
+
}
|
|
363
409
|
/**
|
|
364
410
|
* Get the metric meter for the current activity, with activity-specific tags.
|
|
365
411
|
*
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.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,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
|
@@ -78,10 +78,12 @@ import {
|
|
|
78
78
|
MetricMeter,
|
|
79
79
|
Priority,
|
|
80
80
|
ActivityCancellationDetails,
|
|
81
|
+
IllegalStateError,
|
|
81
82
|
} from '@temporalio/common';
|
|
82
83
|
import { msToNumber } from '@temporalio/common/lib/time';
|
|
83
84
|
import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
|
|
84
85
|
import { ActivityCancellationDetailsHolder } from '@temporalio/common/lib/activity-cancellation-details';
|
|
86
|
+
import { Client } from '@temporalio/client';
|
|
85
87
|
|
|
86
88
|
export {
|
|
87
89
|
ActivityFunction,
|
|
@@ -238,93 +240,82 @@ export class Context {
|
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
/**
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
|
-
public readonly info: Info;
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
247
|
-
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
248
|
-
*
|
|
249
|
-
* 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.
|
|
250
244
|
*
|
|
251
|
-
* @
|
|
245
|
+
* @ignore
|
|
252
246
|
*/
|
|
253
|
-
|
|
247
|
+
constructor(
|
|
248
|
+
/**
|
|
249
|
+
* Holds information about the current executing Activity.
|
|
250
|
+
*/
|
|
251
|
+
public readonly info: Info,
|
|
254
252
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
*
|
|
265
|
-
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
266
|
-
*
|
|
267
|
-
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
268
|
-
*/
|
|
269
|
-
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>,
|
|
270
262
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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,
|
|
275
278
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
|
|
281
|
-
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
|
|
282
|
-
*
|
|
283
|
-
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
|
|
284
|
-
* `getLogAttributes()` method.
|
|
285
|
-
*
|
|
286
|
-
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
|
|
287
|
-
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
|
|
288
|
-
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
289
|
-
* {@link Runtime.logger} property instead.
|
|
290
|
-
*/
|
|
291
|
-
public log: Logger;
|
|
279
|
+
/**
|
|
280
|
+
* The heartbeat implementation, injected via the constructor.
|
|
281
|
+
*/
|
|
282
|
+
protected readonly heartbeatFn: (details?: any) => void,
|
|
292
283
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
* intercepts the `getMetricTags()` method.
|
|
298
|
-
*/
|
|
299
|
-
public readonly metricMeter: MetricMeter;
|
|
284
|
+
/**
|
|
285
|
+
* The Worker's client, passed down through Activity context.
|
|
286
|
+
*/
|
|
287
|
+
protected readonly _client: Client | undefined,
|
|
300
288
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
305
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
) {
|
|
320
|
-
this.info = info;
|
|
321
|
-
this.cancelled = cancelled;
|
|
322
|
-
this.cancellationSignal = cancellationSignal;
|
|
323
|
-
this.heartbeatFn = heartbeat;
|
|
324
|
-
this.log = log;
|
|
325
|
-
this.metricMeter = metricMeter;
|
|
326
|
-
this._cancellationDetails = details;
|
|
327
|
-
}
|
|
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
|
+
) {}
|
|
328
319
|
|
|
329
320
|
/**
|
|
330
321
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
@@ -351,6 +342,25 @@ export class Context {
|
|
|
351
342
|
this.heartbeatFn(details);
|
|
352
343
|
};
|
|
353
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
|
+
|
|
354
364
|
/**
|
|
355
365
|
* Helper function for sleeping in an Activity.
|
|
356
366
|
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
@@ -481,6 +491,22 @@ export function cancellationSignal(): AbortSignal {
|
|
|
481
491
|
return Context.current().cancellationSignal;
|
|
482
492
|
}
|
|
483
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
|
+
|
|
484
510
|
/**
|
|
485
511
|
* Get the metric meter for the current activity, with activity-specific tags.
|
|
486
512
|
*
|