Interface IOutbox

Outbound deliveries: retried with backoff for a day, replayable, content-free after a purge; mail deliveries delivered at most once within their expiry.

interface IOutbox {
    forget?(runId): Promise<void>;
    enqueue(delivery, now): Promise<void>;
    due(now, limit?): Promise<OutboxDelivery[]>;
    markDelivered(id): Promise<void>;
    markFailed(id, now): Promise<void>;
    replay(id, now): Promise<void>;
    markDead?(id): Promise<boolean>;
    holdUntil?(id, notBefore): Promise<boolean>;
    cancel?(runId, destinationRef): Promise<boolean>;
    endExpired?(now): Promise<number>;
    purgeContent(runId): Promise<void>;
    listByRun(runId): Promise<OutboxDelivery[]>;
    sendClaimed?(candidate, send): Promise<boolean>;
}

Implemented by

Methods

  • Optional whole-run eviction for in-memory hosts after terminal cleanup and the retention grace. Durable stores omit it to retain their records. Call only after producers have stopped; forgetting removes fences too.

    Parameters

    • runId: string

    Returns Promise<void>

  • Adds a pending delivery, due at now; a repeated id preserves the first delivery and its retry state. After purgeContent for the run, a delivery of a content event (a type in CONTENT_EVENT_TYPES) is not stored: the purge is the outbox's fence. A delivery of any other type (bot:left, bot:purged, bot:done and the rest) is stored. A mail delivery (kind: 'mail') is content: behind the fence it is stored empty and dead, and purgeContent empties it with the content events.

    Parameters

    Returns Promise<void>

  • Records a failed attempt: due again after the backoff of nextAttemptAt, or dead a day after the first failed attempt, or at a mail delivery's expiry (its body emptied). A delivery that is no longer pending, delivered or dead, is left as it is.

    Parameters

    • id: string
    • now: number

    Returns Promise<void>

  • Makes a delivery pending again, due at now, with its attempts counted afresh (a manual replay); a mail delivery is never replayed, and the call changes nothing.

    Parameters

    • id: string
    • now: number

    Returns Promise<void>

  • Optional (the library's stores have it). Ends a pending delivery at once (a destination's permanent refusal, or an outcome the destination never answered), a mail's body emptied; one no longer pending is left as it is. True when the outbox recorded it; false from a wrapper whose outbox cannot, whose caller records a failed attempt instead.

    Parameters

    • id: string

    Returns Promise<boolean>

  • Optional (the library's stores have it). Moves a pending delivery's next attempt to notBefore without counting an attempt (a cap that holds it). True when recorded; false from a wrapper whose outbox cannot.

    Parameters

    • id: string
    • notBefore: number

    Returns Promise<boolean>

  • Optional (the library's stores have it). Ends every pending delivery of the run to the destination (an address that declined), their bodies emptied. True when recorded; false from a wrapper whose outbox cannot.

    Parameters

    • runId: string
    • destinationRef: string

    Returns Promise<boolean>

  • Optional (the library's stores have it). Ends every pending mail delivery whose expiry has passed at now, dead with its body emptied, so an expired body waits for no attempt; the count ended. OutboxDispatcher calls it at the start of each pass.

    Parameters

    • now: number

    Returns Promise<number>

  • Empties every content delivery of the run (a type in CONTENT_EVENT_TYPES), delivered ones included, so a replay after a purge sends the content-free bot:purged in its place. A delivery of any other type (bot:done, bot:left and the rest) carries no content and keeps its type and payload. From then on the run takes no content delivery (see enqueue).

    Parameters

    • runId: string

    Returns Promise<void>

  • Optional. Sends one delivery under the outbox's own guard: re-reads candidate (a row due returned, which a purge may have emptied since) and, when it is still pending, calls send with the fresh row and a signal that a purge of its run aborts. Answers true when send resolved, false when the delivery was skipped (gone, no longer pending, being sent already, or cancelled by a purge), and rejects with send's error otherwise. OutboxDispatcher sends through it when an outbox has it (InMemoryOutbox, SqlOutbox and FencedOutbox do), and sends the row due returned when it has not.

    Parameters

    • candidate: OutboxDelivery
    • send: ((fresh, signal) => Promise<void>)
        • (fresh, signal): Promise<void>
        • Parameters

          Returns Promise<void>

    Returns Promise<boolean>