Skip to main content

Namespace: worker

The temporal worker connects to the service and runs workflows and activities.

Usage

import { Worker } from '@temporalio/worker';
import * as activities from './activities';

async function run() {
// Step 1: Register Workflows and Activities with the Worker and connect to
// the Temporal server.
const worker = await Worker.create({
workflowsPath: require.resolve('./workflows'),
activities,
taskQueue: 'hello-world',
});
// Worker connects to localhost by default and uses console.error for logging.
// Customize the Worker by passing more options to create():
// https://typescript.temporal.io/api/classes/worker.Worker
// If you need to configure server connection parameters, see docs:
// https://docs.temporal.io/typescript/security#encryption-in-transit-with-mtls

// Step 2: Start accepting tasks on the `hello-world` queue
await worker.run();
}

run().catch((err) => {
console.error(err);
process.exit(1);
});

Namespaces

Classes

Interfaces

References

IllegalStateError

Re-exports IllegalStateError

Type aliases

Headers

Ƭ Headers: Record<string, IPayload>

Headers are just a mapping of header name to Payload


History

Ƭ History: IHistory


InjectedSink

Ƭ InjectedSink<T>: { [P in keyof T]: InjectedSinkFunction<T[P]> }

Converts a Sink from a mapping of name to function to a mapping of name to InjectedSinkFunction

Type parameters

NameType
Textends Sink

InjectedSinks

Ƭ InjectedSinks<T>: { [P in keyof T]: InjectedSink<T[P]> }

Converts a Sinks interface from a mapping of name to Sink to a mapping of name to InjectedSink.

Used for type checking Sink injection against supplied type param T.

Type parameters

NameType
Textends Sinks

LogLevel

Ƭ LogLevel: "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR"

Log level - must match rust log level names


LogMetadata

Ƭ LogMetadata: Record<string | symbol, any>


Next

Ƭ Next<IF, FN>: Required<IF>[FN] extends AnyFunc ? OmitLastParam<Required<IF>[FN]> : never

Type of the next function for a given interceptor function

Called from an interceptor to continue the interception chain

Type parameters

NameType
IFIF
FNextends keyof IF

RequiredNativeConnectionOptions

Ƭ RequiredNativeConnectionOptions: Omit<Required<NativeConnectionOptions>, "tls" | "headers"> & { headers?: NativeConnectionOptions["headers"] ; sdkVersion: string ; tls?: NativeConnectionOptions["tls"] }


State

Ƭ State: "INITIALIZED" | "RUNNING" | "STOPPED" | "STOPPING" | "DRAINING" | "DRAINED" | "FAILED"

The worker's possible states

  • INITIALIZED - The initial state of the Worker after calling Worker.create and successful connection to the server
  • RUNNING - Worker.run was called, polling task queues
  • STOPPING - Worker.shutdown was called or received shutdown signal, worker will forcefully shutdown in shutdownGraceTime
  • DRAINING - Core has indicated that shutdown is complete and all Workflow tasks have been drained, waiting for activities and cached workflows eviction
  • DRAINED - All activities and workflows have completed, ready to shutdown
  • STOPPED - Shutdown complete, Worker.run resolves
  • FAILED - Worker encountered an unrecoverable error, Worker.run should reject with the error

TLSConfig

Ƭ TLSConfig: TLSConfig


TelemLogger

Ƭ TelemLogger: ConsoleLogger | ForwardLogger

Logger types supported by Core

Variables

LogTimestamp

Const LogTimestamp: unique symbol


defaultPayloadConverter

Const defaultPayloadConverter: DefaultPayloadConverter

The default PayloadConverter used by the SDK. Supports Uint8Array and JSON serializables (so if JSON.stringify(yourArgOrRetval) works, the default payload converter will work).

To also support Protobufs, create a custom payload converter with DefaultPayloadConverter:

const myConverter = new DefaultPayloadConverter({ protobufRoot })

Functions

bundleWorkflowCode

bundleWorkflowCode(options): Promise<{ code: string }>

Parameters

NameType
optionsBundleOptions

Returns

Promise<{ code: string }>


timeOfDayToBigint

timeOfDayToBigint(timeOfDay): bigint

Takes a [seconds, nanos] tuple as returned from getTimeOfDay and turns it into bigint.

Parameters

NameType
timeOfDay[number, number]

Returns

bigint