Dex TypeScript SDK 1.35.0
    Preparing search index...

    Class Worker

    Hosts registered Step and RPC handlers through outbound pull streams.

    A Worker is one-shot. Call start to register the first slot or run to await shutdown, then call close. Concurrent handlers must synchronize shared state. close stops new tasks, half-closes idle streams, and lets busy handlers send final output before half-closing. It drains for stopDrainTimeoutMs, then resets streams whose handler has not written final output, cancels those handlers, and waits for them to return. Half-closed streams wait for server EOF until the drain deadline and are then reset. A stream whose final output Dex has not yet confirmed, by ending the stream or assigning its next task, gets 5 more seconds, so close can return up to 5 seconds later. 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, or flowServiceTls is set and the address or TLS settings are 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

      Returns the retained reserved RPC decline counter.

      Returns number

      The constant value zero.

      Reserved slots never decline Steps for capacity. Always returns zero, including after close.

      const legacyCounter = worker.pullReservedRpcDeclines;
      

    Methods

    • Stops new tasks and drains handlers before releasing connections. Idle streams half-close immediately. Busy streams send their final output before half-closing. Tasks arriving after stop begins are dropped without running a handler, including after half-close. Streams keep reading until the Server ends them. After the drain timeout, streams whose handler has not written final output are reset, those handlers are canceled, and close waits for them to return. A handler whose final output is written still half-closes. Half-closed streams that the Server has not ended by the drain deadline are reset. A stream whose final output the Server has not yet confirmed gets a 5-second flush grace after the deadline. The Server confirms it by ending the stream or assigning the slot's next task. Close can therefore return up to 5 seconds after the drain deadline. Dex treats a task dropped on a reset stream as possibly run. Calls before start and repeated calls after shutdown are safe.

      Returns Promise<void>

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

      Returns PullRegistrationState

      Current readiness and slot-kind 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 slot kind without registered streams when stopOnPermanentStreamRejection is enabled.

    • Negotiates the Server protocol, synchronizes indexes, and starts polling. The promise resolves after the first slot registers and its Server concurrency limit is checked; call exactly once. Await waitPullRegistered separately to gate readiness on both configured slot kinds.

      Returns Promise<void>

      A promise resolved after protocol negotiation, index synchronization, and the first registration.

      The Server is incompatible, unreachable (the gRPC error is the cause), or startup fails.

      maxConcurrentTasks exceeds matching.maxConcurrentTasksCap; the Worker half-closes its streams.

      The Server permanently rejects every stream before any registers.

    • Waits until at least one STEP_AND_RPC stream and, when reserved, one RPC_ONLY stream have registered. 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 configured slot kinds have registered once.

      A permanent rejection leaves a slot kind 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);