Skip to content

Commit 3979d2a

Browse files
authored
Convert Activity's Context class to contructor-args-as-fields notation (#1770)
1 parent 1df75b0 commit 3979d2a

File tree

1 file changed

+67
-85
lines changed

1 file changed

+67
-85
lines changed

packages/activity/src/index.ts

Lines changed: 67 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -240,100 +240,82 @@ 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 Worker's client, passed down through Activity context.
280-
*/
281-
protected readonly _client: Client | undefined;
279+
/**
280+
* The heartbeat implementation, injected via the constructor.
281+
*/
282+
protected readonly heartbeatFn: (details?: any) => void,
282283

283-
/**
284-
* The logger for this Activity.
285-
*
286-
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
287-
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
288-
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
289-
*
290-
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
291-
* `getLogAttributes()` method.
292-
*
293-
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
294-
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
295-
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
296-
* {@link Runtime.logger} property instead.
297-
*/
298-
public log: Logger;
284+
/**
285+
* The Worker's client, passed down through Activity context.
286+
*/
287+
protected readonly _client: Client | undefined,
299288

300-
/**
301-
* Get the metric meter for this activity with activity-specific tags.
302-
*
303-
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
304-
* intercepts the `getMetricTags()` method.
305-
*/
306-
public readonly metricMeter: MetricMeter;
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,
307305

308-
/**
309-
* Holder object for activity cancellation details
310-
*/
311-
private readonly _cancellationDetails: ActivityCancellationDetailsHolder;
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,
312313

313-
/**
314-
* **Not** meant to instantiated by Activity code, used by the worker.
315-
*
316-
* @ignore
317-
*/
318-
constructor(
319-
info: Info,
320-
cancelled: Promise<never>,
321-
cancellationSignal: AbortSignal,
322-
heartbeat: (details?: any) => void,
323-
client: Client | undefined,
324-
log: Logger,
325-
metricMeter: MetricMeter,
326-
details: ActivityCancellationDetailsHolder
327-
) {
328-
this.info = info;
329-
this.cancelled = cancelled;
330-
this.cancellationSignal = cancellationSignal;
331-
this.heartbeatFn = heartbeat;
332-
this._client = client;
333-
this.log = log;
334-
this.metricMeter = metricMeter;
335-
this._cancellationDetails = details;
336-
}
314+
/**
315+
* Holder object for activity cancellation details
316+
*/
317+
protected readonly _cancellationDetails: ActivityCancellationDetailsHolder
318+
) {}
337319

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

0 commit comments

Comments
 (0)