UNPKG

@temporalio/worker

Version:
48 lines (47 loc) 2.58 kB
import 'abort-controller/polyfill'; import { Context, Info } from '@temporalio/activity'; import { ActivityFunction, LoadedDataConverter, MetricMeter, MetricTags } from '@temporalio/common'; import { Logger } from '@temporalio/common/lib/logger'; import { coresdk } from '@temporalio/proto'; import { ActivityExecuteInput, ActivityInboundCallsInterceptor, ActivityInterceptorsFactory, ActivityOutboundCallsInterceptor } from './interceptors'; export type CancelReason = keyof typeof coresdk.activity_task.ActivityCancelReason | 'WORKER_SHUTDOWN' | 'HEARTBEAT_DETAILS_CONVERSION_FAILED'; export declare class Activity { readonly info: Info; readonly fn: ActivityFunction<any[], any> | undefined; readonly dataConverter: LoadedDataConverter; readonly heartbeatCallback: Context['heartbeat']; protected cancelReason?: CancelReason; readonly context: Context; cancel: (reason: CancelReason) => void; readonly abortController: AbortController; readonly interceptors: { inbound: ActivityInboundCallsInterceptor[]; outbound: ActivityOutboundCallsInterceptor[]; }; /** * Logger bound to `sdkComponent: worker`, with metadata from this activity. * This is the logger to use for all log messages emitted by the activity * worker. Note this is not exactly the same thing as the activity context * logger, which is bound to `sdkComponent: activity`. */ private readonly workerLogger; /** * Metric Meter with tags from this activity, including tags from interceptors. */ private readonly metricMeter; constructor(info: Info, fn: ActivityFunction<any[], any> | undefined, dataConverter: LoadedDataConverter, heartbeatCallback: Context['heartbeat'], workerLogger: Logger, workerMetricMeter: MetricMeter, interceptors: ActivityInterceptorsFactory[]); protected getLogAttributes(): Record<string, unknown>; protected getMetricTags(): MetricTags; /** * Actually executes the function. * * Any call up to this function and including this one will be trimmed out of stack traces. */ protected execute(fn: ActivityFunction<any[], any>, input: ActivityExecuteInput): Promise<unknown>; run(input: ActivityExecuteInput): Promise<coresdk.activity_result.IActivityExecutionResult>; runNoEncoding(fn: ActivityFunction<any[], any>, input: ActivityExecuteInput): Promise<unknown>; } /** * Returns a map of attributes to be set on log messages for a given Activity */ export declare function activityLogAttributes(info: Info): Record<string, unknown>;