Class: Worker
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:228
The temporal Worker connects to Temporal Server and runs Workflows and Activities.
Properties
options
readonlyoptions:CompiledWorkerOptions
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:235
Accessors
client
Get Signature
get client():
Client|undefined
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:334
Get the client associated with this Worker.
Returns undefined if the worker was created without a connection (e.g., replay workers).
Returns
Client | undefined
connection
Get Signature
get connection():
NativeConnection|undefined
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:339
Get the connection associated with this Worker. Returns undefined if the worker was created without a connection (e.g., replay workers).
Returns
NativeConnection | undefined
Set Signature
set connection(
newConnection):void
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:354
Replace the connection used by this Worker. This allows the worker to switch to a different Temporal server or update connection configuration without restarting the worker.
Remarks
The worker must have been created with a connection for this method to work. Subsequent calls by the worker to Temporal (e.g., responding to tasks) will use the new connection. A new client will be created automatically from the provided connection.
Throws
If the worker was created without a connection
Throws
If the connection replacement fails
Parameters
newConnection
NativeConnection
The new NativeConnection to use
Returns
void
numInFlightActivations$
Get Signature
get numInFlightActivations$():
Observable<number>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:312
An Observable which emits each time the number of in flight activations changes
Returns
Observable<number>
numInFlightActivities$
Get Signature
get numInFlightActivities$():
Observable<number>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:316
An Observable which emits each time the number of in flight Activity tasks changes
Returns
Observable<number>
numRunningWorkflowInstances$
Get Signature
get numRunningWorkflowInstances$():
Observable<number>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:320
An Observable which emits each time the number of cached workflows changes
Returns
Observable<number>
Methods
getState()
getState():
State
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:324
Get the poll state of this worker
Returns
State
getStatus()
getStatus():
WorkerStatus
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:328
Get a status overview of this Worker
Returns
WorkerStatus
run()
run():
Promise<void>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:478
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.
Returns
Promise<void>
See
errors
To stop polling, call shutdown or send one of Runtime.options.shutdownSignals.
runUntil()
runUntil<
R>(fnOrPromise,options?):Promise<R>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:467
Run the Worker until fnOrPromise completes, then shutdown and wait for run to complete.
Be aware that the Worker may shutdown for reasons other than the completion of the provided promise,
e.g. due to the process receiving a SIGINT signal, direct call to Worker.shutdown(), or a critical
error that imposes a shutdown of the Worker.
Throws on fatal Worker errors.
SDK versions >=1.11.3:
If the worker shuts down before the inner promise completes, allow no more than
RunUntilOptions.promiseCompletionTimeout for the inner promise to complete,
after which a PromiseCompletionTimeoutError is thrown.
SDK versions >=1.5.0:
This method always waits for both worker shutdown and inner fnOrPromise to complete.
If one of worker run -or- the inner promise throw an error, that error is rethrown.
If both throw an error, a CombinedWorkerRunError with a cause attribute containing both errors.
SDK versions < 1.5.0:
This method would not wait for worker to complete shutdown if the inner fnOrPromise threw an error.
Type Parameters
R
R
Parameters
fnOrPromise
Promise<R> | (() => Promise<R>)
options?
RunUntilOptions
Returns
Promise<R>
the result of fnOrPromise
shutdown()
shutdown():
void
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:373
Start shutting down the Worker. The Worker stops polling for new tasks and sends
cancellation
(via a CancelledFailure with message set to 'WORKER_SHUTDOWN') to running Activities.
Note: if the Activity accepts cancellation (i.e. re-throws or allows the CancelledFailure
to be thrown out of the Activity function), the Activity Task will be marked as failed, not
cancelled. It's helpful for the Activity Task to be marked failed during shutdown because the
Server will retry the Activity sooner (than if the Server had to wait for the Activity Task
to time out).
When called, 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. It will
stay in that state until both task pollers receive a ShutdownError, at which point we'll
transition to DRAINED state. Once all currently running Activities and Workflow Tasks have
completed, the Worker transitions to 'STOPPED'.
Returns
void
create()
staticcreate(options):Promise<Worker>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:278
Create a new Worker. This method initiates a connection to the server and will throw (asynchronously) on connection failure.
Parameters
options
WorkerOptions
Returns
Promise<Worker>
runReplayHistories()
staticrunReplayHistories(options,histories):AsyncIterableIterator<ReplayResult>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:295
Create a replay Worker, running all histories provided by the passed in iterable.
Returns an async iterable of results for each history replayed.
Parameters
options
ReplayWorkerOptions
histories
ReplayHistoriesIterable
Returns
AsyncIterableIterator<ReplayResult>
runReplayHistory()
staticrunReplayHistory(options,history,workflowId?):Promise<void>
Defined in: node_modules/@temporalio/worker/lib/worker.d.ts:289
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.
Parameters
options
ReplayWorkerOptions
history
unknown
workflowId?
string
If provided, use this as the workflow id during replay. Histories do not contain a workflow id, so it must be provided separately if your workflow depends on it.
Returns
Promise<void>
Throws
DeterminismViolationError if the workflow code is not compatible with the history.
Throws
ReplayError on any other replay related error.