Skip to main content

Class: Worker

worker.Worker

The temporal Worker connects to Temporal Server and runs Workflows and Activities.

Properties

options

Readonly options: CompiledWorkerOptions

Accessors

numInFlightActivations$

get numInFlightActivations$(): Observable<number>

An Observable which emits each time the number of in flight activations changes

Returns

Observable<number>


numInFlightActivities$

get numInFlightActivities$(): Observable<number>

An Observable which emits each time the number of in flight Activity tasks changes

Returns

Observable<number>


numRunningWorkflowInstances$

get numRunningWorkflowInstances$(): Observable<number>

An Observable which emits each time the number of cached workflows changes

Returns

Observable<number>

Methods

getState

getState(): State

Get the poll state of this worker

Returns

State


getStatus

getStatus(): WorkerStatus

Get a status overview of this Worker

Returns

WorkerStatus


run

run(): Promise<void>

Start polling on tasks, completes after graceful shutdown. Throws on a fatal error or failure to shutdown gracefully.

see errors

To stop polling call shutdown or send one of {@link Worker.options.shutdownSignals}.

Returns

Promise<void>


runUntil

runUntil<R>(fnOrPromise): Promise<R>

Run the Worker until fnOrPromise completes.

Type parameters

Name
R

Parameters

NameType
fnOrPromisePromise<R> | () => Promise<R>

Returns

Promise<R>

the result of fnOrPromise

Throws on fatal Worker errors.


shutdown

shutdown(): void

Start shutting down the Worker. Immediately transitions state to STOPPING and asks Core to shut down. Once Core has confirmed that it's shutting down the Worker enters DRAINING state unless the Worker has already been DRAINED. {@see State}.

Returns

void


create

Static create(options): Promise<Worker>

Create a new Worker. This method initiates a connection to the server and will throw (asynchronously) on connection failure.

Parameters

NameType
optionsWorkerOptions

Returns

Promise<Worker>


runReplayHistory

Static runReplayHistory(options, history): Promise<void>

Create a replay Worker, and run the provided history against it. Will resolve as soon as the history has finished being replayed, or if the workflow produces a nondeterminism error.

throws DeterminismViolationError if the workflow code is not compatible with the history.

Parameters

NameType
optionsReplayWorkerOptions
historyIHistory

Returns

Promise<void>