Anchorage API reference
    Preparing search index...

    The D1 schedules domain: workflow + agent schedule rows and their trigger history. Mirrors core's SchedulesStorage contract exactly (the abstract methods mastra.schedules drives + the scheduler tick reads), so a host that composes it into createD1Storage({ domains }) gets D1-durable schedules with no adapter change.

    Hierarchy

    • SchedulesStorage
      • D1SchedulesStorage
    Index

    Constructors

    Methods

    • Lease one target-side signal attempt. A retry waits while the lease is live and replays a settled receipt. After an ambiguous crash, lease takeover repeats the same stable dispatch id: delivery is deliberately at-least-once because the agent action and D1 receipt cannot be committed in one transaction.

      Parameters

      • scheduleId: string
      • triggerId: string
      • now: number = ...
      • leaseMs: number = 60_000

      Returns Promise<ScheduleAgentDispatchState>

    • Insert a new schedule row. Throws if a row with the same id already exists. Returns the stored row.

      Parameters

      • schedule: Schedule

      Returns Promise<Schedule>

    • Make terminal-run discard authoritative for the exact leased run. A schedule signal may have observed a suspension and settled a wake just before terminal cleanup acquired the target-thread FIFO. That same-run receipt is safe to replace; unrelated or non-execution receipts fail closed.

      Parameters

      • scheduleId: string
      • triggerId: string
      • runId: string

      Returns Promise<void>

    • Read the exact claimed fire a target Durable Object is allowed to execute. Prepared, executing, and settled are one target-side lease lifecycle; the deferred trigger remains the authority until the tick settles its outcome. A schedule id without its atomically claimed trigger and run id is never an execution capability.

      Parameters

      • scheduleId: string
      • dispatchId: string
      • runId: string

      Returns Promise<ScheduleTrigger | null>

    • Get a single schedule by id. Returns null if not found.

      Parameters

      • id: string

      Returns Promise<Schedule | null>

    • Initialize the storage domain. This should create any necessary tables/collections. Default implementation is a no-op - override in adapters that need initialization.

      Returns Promise<void>

    • List schedules whose nextFireAt <= now and whose status === 'active'. Used by the scheduler tick loop.

      Parameters

      • now: number
      • Optionallimit: number

      Returns Promise<Schedule[]>

    • List schedules matching the filter (no pagination — schedule counts are expected to stay small).

      Parameters

      • Optionalfilter: ScheduleFilter

      Returns Promise<Schedule[]>

    • List trigger history for a schedule, newest first.

      Parameters

      • scheduleId: string
      • Optionalopts: ScheduleTriggerListOptions

      Returns Promise<ScheduleTrigger[]>

    • Append an entry to a schedule's trigger history.

      Parameters

      • trigger: ScheduleTrigger

      Returns Promise<void>

    • Merge tick-owned retry diagnostics into a deferred trigger. Target-side dispatch state can change between the tick's read and this write, so a full-row replacement here would erase the current lease or receipt.

      Parameters

      • id: string
      • scheduleId: string
      • error: string | undefined
      • metadata: Record<string, unknown>

      Returns Promise<void>

    • Partial update of a schedule row.

      Parameters

      • id: string
      • patch: ScheduleUpdate

      Returns Promise<Schedule>

    • Compare-and-swap update of nextFireAt. Used by the scheduler to claim a fire before publishing — only one tick across many processes will succeed.

      Returns true if the row's nextFireAt matched expectedNextFireAt and was advanced to newNextFireAt. Returns false if another instance already advanced it (meaning the caller should skip publishing).

      Parameters

      • id: string
      • expectedNextFireAt: number
      • newNextFireAt: number
      • lastFireAt: number
      • lastRunId: string

      Returns Promise<boolean>