Anchorage API reference
    Preparing search index...
    interface BackgroundTaskHostOptions {
        execution?: boolean;
        executionFence: ExecutionFenceWiring;
        executors: Record<string, ToolExecutor>;
        manager?: Omit<BackgroundTaskManagerConfig, "enabled">;
        mastra: Mastra;
        pubsub: PubSub;
    }
    Index

    Properties

    execution?: boolean

    Enable real evented-worker execution for this Durable Object. Omit to preserve the persistence/recovery-only behavior.

    executionFence: ExecutionFenceWiring

    The deployment execution fence, or 'none' for a host with no database behind it. Task bodies are an execution family that runs BELOW RunnerRuntime, so the runtime's start/resume gate does not see them; this is where they are gated instead.

    The gate is at the DISPATCHER, read once per boot pass: behind a closed fence this instance never subscribes and never runs stale-task recovery, so nothing is claimed — queued rows stay pending and stranded rows stay stranded (#ensureDispatching explains why anything later than that is too late). The executor wrapper remains as a fail-closed backstop for the in-flight race, and parks rather than fails.

    REQUIRED: this is the ONLY gate task bodies pass, so an unfenced host runs them straight through a migration lock — and it looks wired, because every other surface of the same deployment reports the fence. See ExecutionFenceWiring.

    draining still dispatches and still accepts enqueues: that queue is the work a drain exists to finish, and refusing an enqueue would fail the very runs that are draining.

    executors: Record<string, ToolExecutor>

    Static tool executors, keyed by tool name, RE-REGISTERED at every boot so a task recovered on a fresh DO instance (post-eviction) resolves its executor by name. Tools are static — their executor closures are safe to rebuild deterministically at boot, unlike per-task closures which core documents are "never serialized".

    manager?: Omit<BackgroundTaskManagerConfig, "enabled">

    Manager config (core BackgroundTaskManagerConfig minus enabled, which is forced on): concurrency, backpressure ('queue'|'reject'|'fallback-sync'), timeouts, retries, and cleanup TTLs. Numeric values are validated before constructing core's manager: concurrency/retry delays/TTLs/throttle are nonnegative, timeout/cleanup intervals are positive, and all integer quantities must be safe integers. Omitted => core defaults.

    mastra: Mastra

    The DO's Mastra — must carry a storage adapter whose getStore('backgroundTasks') resolves (D1Store does). The manager reads every task through it.

    pubsub: PubSub

    The Durable Object's single raw pubsub instance from createHostPubSub(). Pass this same object to new Mastra({ pubsub }); Mastra 1.50 exposes a proxy from its public pubsub getter, so that getter is not the constructor identity. The manager both publishes dispatch events and subscribes the worker callback on the raw instance, and inside a DO one isolate serializes publisher and subscriber, so an in-process EventEmitterPubSub is exactly right (no cross-process bus). A host that streams lifecycle events to its hub also passes this same raw instance to init().