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 the Task Queue for tasks. Completes after graceful shutdown, once the Worker reaches the 'STOPPED' state.

Throws on a fatal error or failure to shutdown gracefully.

See

errors

To stop polling, call shutdown or send one of Runtime.options.shutdownSignals.

Returns

Promise<void>


runUntil

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

Run the Worker until fnOrPromise completes. Then shutdown and wait for run to complete.

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'. Once all currently running Activities and Workflow Tasks have completed, the Worker transitions to 'STOPPED'.

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
historyunknown

Returns

Promise<void>