Skip to content

Commit 9885140

Browse files
committed
Normalize activity's Context around the constructor-arg-as-fields syntax
1 parent 6dae17d commit 9885140

File tree

1 file changed

+65
-80
lines changed

1 file changed

+65
-80
lines changed

packages/activity/src/index.ts

Lines changed: 65 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -240,94 +240,79 @@ export class Context {
240240
}
241241

242242
/**
243-
* Holds information about the current executing Activity.
244-
*/
245-
public readonly info: Info;
246-
247-
/**
248-
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
249-
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
250-
*
251-
* 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.
252244
*
253-
* @see [Cancellation](/api/namespaces/activity#cancellation)
245+
* @ignore
254246
*/
255-
public readonly cancelled: Promise<never>;
247+
constructor(
248+
/**
249+
* Holds information about the current executing Activity.
250+
*/
251+
public readonly info: Info,
256252

257-
/**
258-
* An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
259-
* Activity cancellation.
260-
*
261-
* This can be passed in to libraries such as
262-
* {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
263-
* in-progress request and
264-
* {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
265-
* to abort a child process, as well as other built-in node modules and modules found on npm.
266-
*
267-
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
268-
*
269-
* @see [Cancellation](/api/namespaces/activity#cancellation)
270-
*/
271-
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>,
272262

273-
/**
274-
* The heartbeat implementation, injected via the constructor.
275-
*/
276-
protected readonly heartbeatFn: (details?: any) => void;
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,
277278

278-
/**
279-
* The logger for this Activity.
280-
*
281-
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
282-
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
283-
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
284-
*
285-
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
286-
* `getLogAttributes()` method.
287-
*
288-
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
289-
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
290-
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
291-
* {@link Runtime.logger} property instead.
292-
*/
293-
public log: Logger;
279+
/**
280+
* The heartbeat implementation, injected via the constructor.
281+
*/
282+
protected readonly heartbeatFn: (details?: any) => void,
294283

295-
/**
296-
* Get the metric meter for this activity with activity-specific tags.
297-
*
298-
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
299-
* intercepts the `getMetricTags()` method.
300-
*/
301-
public readonly metricMeter: MetricMeter;
284+
private readonly _client: Client | undefined,
302285

303-
/**
304-
* Holder object for activity cancellation details
305-
*/
306-
private readonly _cancellationDetails: ActivityCancellationDetailsHolder;
286+
/**
287+
* The logger for this Activity.
288+
*
289+
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
290+
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
291+
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
292+
*
293+
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
294+
* `getLogAttributes()` method.
295+
*
296+
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
297+
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
298+
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
299+
* {@link Runtime.logger} property instead.
300+
*/
301+
public log: Logger,
307302

308-
/**
309-
* **Not** meant to instantiated by Activity code, used by the worker.
310-
*
311-
* @ignore
312-
*/
313-
constructor(
314-
info: Info,
315-
cancelled: Promise<never>,
316-
cancellationSignal: AbortSignal,
317-
heartbeat: (details?: any) => void,
318-
private readonly _client: Client | undefined,
319-
log: Logger,
320-
metricMeter: MetricMeter,
321-
details: ActivityCancellationDetailsHolder
322-
) {
323-
this.info = info;
324-
this.cancelled = cancelled;
325-
this.cancellationSignal = cancellationSignal;
326-
this.heartbeatFn = heartbeat;
327-
this.log = log;
328-
this.metricMeter = metricMeter;
329-
this._cancellationDetails = details;
330-
}
303+
/**
304+
* Get the metric meter for this activity with activity-specific tags.
305+
*
306+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
307+
* intercepts the `getMetricTags()` method.
308+
*/
309+
public readonly metricMeter: MetricMeter,
310+
311+
/**
312+
* Holder object for activity cancellation details
313+
*/
314+
private readonly _cancellationDetails: ActivityCancellationDetailsHolder
315+
) {}
331316

332317
/**
333318
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.

0 commit comments

Comments
 (0)