Postgres dispatch jobs with atomic leases and holder-checked writes.

Implements

Constructors

Methods

  • Schedules a job; an existing job keeps its lease, dispatch and cancellation fields.

    Parameters

    • job: {
          runId: string;
          dispatchAt: number;
      }
      • runId: string
      • dispatchAt: number

    Returns Promise<void>

  • Records the holder's dispatch and reports a cancellation that arrived during it.

    Parameters

    • runId: string
    • holder: string
    • workerId: undefined | string

    Returns Promise<{
        recorded: boolean;
        cancelled: boolean;
    }>

  • Cancels a pending job or reports that the caller must leave an already dispatched bot.

    Parameters

    • runId: string

    Returns Promise<"cancelled" | "already_dispatched" | "missing">