Dex TypeScript SDK 1.29.0
    Preparing search index...

    Class Worker

    Hosts registered Step and RPC handlers through outbound pull streams.

    A Worker is one-shot. Call start for non-blocking startup or run to await shutdown, then call close. Concurrent handlers must synchronize shared state. close drains for stopDrainTimeoutMs, then cancels handlers and waits for them to return. Half-closed streams wait for server EOF until the remaining drain deadline. A handler that ignores cancellation can delay shutdown.

    const worker = new Worker(registry, cache);
    await worker.start();
    try { await worker.waitPullRegistered({ timeoutMs: 10_000 }); } finally { await worker.close(); }
    Index

    Constructors

    • Constructs a Worker without starting its task streams. Workers need only an outbound connection to the Dex Server.

      Parameters

      • registry: Registry

        Flow definitions served by this Worker.

      • blobCache: BlobCache

        Open cache used to hydrate large handler values.

      • options: WorkerOptions = {}

        Server connectivity, task capacity, bearer credential, and startup settings; uses local defaults when omitted.

      Returns Worker

      When the Worker ID is invalid.

      When a pull capacity or drain timeout is invalid.

    Properties

    blobCache: BlobCache

    Open cache used to hydrate large handler values.

    options: WorkerOptions = {}

    Server connectivity, task capacity, bearer credential, and startup settings; uses local defaults when omitted.

    registry: Registry

    Flow definitions served by this Worker.

    Accessors

    • get pullReservedRpcDeclines(): number

      Cumulative Step declines caused by reserved RPC capacity during this Worker's lifetime. Counts decline events. Dex may decline the same Step dispatch repeatedly while retrying it, so read the counter as a rate. Excludes full-capacity rejections and unknown names. The count never resets and remains available after close. Reading during handler execution is safe. Export the value to a monitoring counter.

      Returns number

      The cumulative reserve-decline count.

      const declines = worker.pullReservedRpcDeclines;
      

    Methods

    • Gracefully drains tasks, then releases connections. A pull Worker force-cancels after its drain timeout and waits for handlers to return. Half-closed pull streams wait for server EOF until the remaining drain deadline. Calls before start and repeated calls after shutdown are safe.

      Returns Promise<void>

    • Returns an independent snapshot of pull queue registrations. Readiness latches after every queue registers once. Only a permanent rejection with no registered stream makes it false; re-registration clears the queue error. Stop preserves readiness.

      Returns PullRegistrationState

      Current readiness and queue snapshots. See waitPullRegistered for a startup and readiness example. Treat errors as immutable.

    • Starts the Worker and waits until close completes shutdown.

      Returns Promise<void>

      A promise resolved after graceful shutdown and handler completion.

      Startup or shutdown fails.

      A permanent rejection leaves a queue without registered streams when stopOnPermanentStreamRejection is enabled.

    • Negotiates the Server protocol, synchronizes indexes, and starts polling. The promise resolves after launching pull streams; call exactly once. Await waitPullRegistered separately to gate startup on pull queue acknowledgements.

      Returns Promise<void>

    • Waits until every Flow type queue and the app Worker ID queue has registered at least once. Safe before or after start and for concurrent callers. Later calls resolve even after shutdown. Reconnects do not reset completion. Use pullRegistrationState for ongoing readiness probes.

      Parameters

      • options: WaitPullRegisteredOptions = {}

        Optional AbortSignal and positive timeout in milliseconds; defaults to waiting indefinitely.

      Returns Promise<void>

      A promise resolved after all queues have registered once.

      A permanent rejection leaves a queue without another registered stream before readiness.

      Startup fails or the Worker stops before readiness.

      The timeout is invalid.

      The timeout expires; cancellation rejects with the signal's reason.

      await worker.start();
      await worker.waitPullRegistered({ timeoutMs: 10_000 });
      console.log(worker.pullRegistrationState().isReady);