---
title: "Hooks and guarantees"
description: "Every function an app hands a setup helper for the package to call: where it runs, how often, in which order, what a throw does, and the idempotency it needs."
canonical_url: "https://nuxt-backend.dev/docs/reference/backend/hooks"
---
# Hooks and guarantees

> Every function an app hands a setup helper for the package to call: where it runs, how often, in which order, what a throw does, and the idempotency it needs.

Version: nuxt-backend 0.6.x · Tab: Reference · Kind: reference · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/client/auth-types.ts)

A hook is a function your `backend/` files pass to a setup helper, which the package calls at a point of its own. This page lists every hook with where it runs, how often, in which order, what a throw does and the idempotency it needs, so you can write one the package calls safely. Each one runs with a Convex ctx, so it can read your tables and schedule work. The list is generated from the helpers' option types, and a hook added to an option type cannot ship without its promises.

Two rules hold for every hook. A webhook handler can run twice for one event, so key what it writes on the event's id. A gate (`canSignIn`, `canGift`, `resolveEntity`, `requireAdmin`) is a read: it can run more than once for one request.

When an account is created, `canSignIn` runs after the launch rules of `setupAccess` (passed to `setupAuth` as `access`), as a veto of your own. On a code request it runs first, with `ticket: null`, and the launch phase's ticket check follows once the code checks. `setupAccount`'s sources erase their rows when an account's grace period ends, unless the account has become the only owner of a workspace others belong to: its deletion then moves a day on, until ownership moves or the others leave. An administrator's removal and `account.forget` start the erasure at once: a source that keeps failing is retried, then logged as `account.erasure_failed` and recorded for administrators, so an erasure is done only once every source finished.

## Hooks

### `setupAuth({ onUserCreated })`

Fired after an account is created, after its welcome email.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the auth request that created the account (a mutation or action ctx), after its welcome email
    </td>
    
    <td>
      Once, or twice when it throws: Better Auth runs a failed after-hook a second time
    </td>
    
    <td>
      After the account is created
    </td>
    
    <td>
      Run again once; a second throw fails the sign-up request, and the account stays created
    </td>
    
    <td>
      Key what it starts on <code>
        user.id
      </code>
      
      , since it can run twice
    </td>
  </tr>
</tbody>
</table>

### `setupAuth({ canSignIn })`

Gate sign-in / sign-up (invite-only, allow-list, closed beta).

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the auth request (a mutation or action ctx), before the write it guards
    </td>
    
    <td>
      Every time the gate is asked: a code request, an account creation, each new session, and twice for an email change
    </td>
    
    <td>
      Before any write, so a refusal leaves nothing behind
    </td>
    
    <td>
      The error propagates as thrown and fails the request; return <code>
        { allowed: false }
      </code>
      
       to refuse with <code>
        forbidden
      </code>
      
      , reason <code>
        sign_in_refused
      </code>
    </td>
    
    <td>
      A read only: it runs several times for one sign-in
    </td>
  </tr>
</tbody>
</table>

### `setupAuth({ onUserDeleted })`

Fired after an account is deleted, after any consumer `afterDelete`.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the deletion request (a mutation or action ctx), after the app's own <code>
        user.deleteUser.afterDelete
      </code>
    </td>
    
    <td>
      Once per deletion
    </td>
    
    <td>
      After the account is deleted
    </td>
    
    <td>
      The deletion request fails; the account is already deleted
    </td>
    
    <td>
      Make the erasure safe to run again, by <code>
        user.id
      </code>
    </td>
  </tr>
</tbody>
</table>

### `setupBilling({ resolveEntity })`

Resolve the billing entity yourself, in place of the identity claims `billTo` reads.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In every billing function's ctx: a query, a mutation or an action
    </td>
    
    <td>
      On every billing call, the reads included
    </td>
    
    <td>
      Before the call reads or writes anything
    </td>
    
    <td>
      A refusal it throws answers the reads with <code>
        null
      </code>
      
       and refuses the rest
    </td>
    
    <td>
      A read only; return <code>
        null
      </code>
      
       when there is no identity
    </td>
  </tr>
</tbody>
</table>

### `setupBilling({ requireAdmin })`

Gate the admin-tier billing functions (`refundOrder` — moving real money — and the webhook delivery log).

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the admin-tier function's ctx (<code>
        refundOrder
      </code>
      
      , the webhook log)
    </td>
    
    <td>
      On every admin-tier call
    </td>
    
    <td>
      After the impersonation refusal, before the call
    </td>
    
    <td>
      The call is refused
    </td>
    
    <td>
      A read only
    </td>
  </tr>
</tbody>
</table>

### `setupBilling({ events })`

React to billing webhook events, keyed by the provider's own event names (`'order.paid'`, `'subscription.active'`, …).

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the webhook's HTTP action, after the built-in entitlement refresh and gift fulfilment
    </td>
    
    <td>
      At least once: a delivery already processed answers 200 without running it again, but one that threw is redelivered
    </td>
    
    <td>
      As the provider delivers: no order across events
    </td>
    
    <td>
      Logged as <code>
        handler_error
      </code>
      
      , answered 500, and the provider retries
    </td>
    
    <td>
      Key what it writes on the event's id
    </td>
  </tr>
</tbody>
</table>

### `setupBilling({ canGift })`

Decide who may receive a gift, before `giftCheckout` opens the purchaser's checkout — only addresses on your own domain, say, or only sandbox addresses on a public demo.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In <code>
        giftCheckout
      </code>
      
      's action ctx, after the package's own gift rules
    </td>
    
    <td>
      Once per gift checkout
    </td>
    
    <td>
      Before the purchaser's checkout opens
    </td>
    
    <td>
      The error fails the gift checkout; return a refusal instead, whose message reaches the purchaser as <code>
        forbidden
      </code>
      
      , reason <code>
        gift_refused
      </code>
    </td>
    
    <td>
      A read only
    </td>
  </tr>
</tbody>
</table>

### `setupBilling({ checkoutDiscount })`

Pick a server-side discount for a plan's checkout: the key of a catalog discount, or `null` for none.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the checkout's action ctx, after the caller and every input are checked
    </td>
    
    <td>
      Once per checkout of a catalog plan that names no discount of its own
    </td>
    
    <td>
      Before the provider checkout is created
    </td>
    
    <td>
      The checkout fails with the error
    </td>
    
    <td>
      A read only
    </td>
  </tr>
</tbody>
</table>

### `setupBilling({ onUnknownEvent })`

Called for an **authentic** (signature-verified) webhook event whose type this package's provider SDK cannot parse — e.g. an event newer than the installed package.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the webhook's HTTP action, for a verified event of a type this package does not know
    </td>
    
    <td>
      At least once: answered 202 when it returns, and redelivered when it throws
    </td>
    
    <td>
      As the provider delivers: no order across events
    </td>
    
    <td>
      Logged as <code>
        handler_error
      </code>
      
      , answered 500, and the provider retries
    </td>
    
    <td>
      Key what it writes on the event's id
    </td>
  </tr>
</tbody>
</table>

### `setupEmail({ events })`

React to any verified provider event, keyed by its event name (`'email.bounced'`, `'contact.created'`, …).

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the webhook's HTTP action, after the email's delivery status is updated
    </td>
    
    <td>
      At least once: a delivery already processed answers 200 without running it again, but one that threw is redelivered
    </td>
    
    <td>
      As the provider delivers: no order across events
    </td>
    
    <td>
      Logged as <code>
        handler_error
      </code>
      
      , answered 500, and the provider retries
    </td>
    
    <td>
      Key what it writes on the event's id
    </td>
  </tr>
</tbody>
</table>

### `setupEmail({ onUnknownEvent })`

Called for a **verified** event whose type is outside the known catalog (a provider newer than this package).

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the webhook's HTTP action, for a verified event of a type this package does not know
    </td>
    
    <td>
      At least once: answered 202 when it returns, and redelivered when it throws
    </td>
    
    <td>
      As the provider delivers: no order across events
    </td>
    
    <td>
      Logged as <code>
        handler_error
      </code>
      
      , answered 500, and the provider retries
    </td>
    
    <td>
      Key what it writes on the event's id
    </td>
  </tr>
</tbody>
</table>

### `setupEmail({ inbound.onReply })`

Called when a person replies by email to a reply address (`email.replyAddress`), once the sender passed DMARC and is that person's own address.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the webhook's HTTP action, after the message is verified and stored
    </td>
    
    <td>
      At least once: a message already handled answers 200 without running it again, but one whose hook threw is redelivered
    </td>
    
    <td>
      As the provider delivers: no order across messages
    </td>
    
    <td>
      Logged as <code>
        handler_error
      </code>
      
      , answered 500, and the provider delivers the message again; the stored copy is not duplicated
    </td>
    
    <td>
      Key what it writes on <code>
        message.id
      </code>
    </td>
  </tr>
</tbody>
</table>

### `setupEmail({ inbound.onWorkspaceMail })`

Called when mail arrives at a workspace's own address on the receiving domain (its slug), once the sender passed the DMARC check.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the webhook's HTTP action, after the message is verified and stored
    </td>
    
    <td>
      At least once: a message already handled answers 200 without running it again, but one whose hook threw is redelivered
    </td>
    
    <td>
      As the provider delivers: no order across messages
    </td>
    
    <td>
      Logged as <code>
        handler_error
      </code>
      
      , answered 500, and the provider delivers the message again; the stored copy is not duplicated
    </td>
    
    <td>
      Key what it writes on <code>
        message.id
      </code>
    </td>
  </tr>
</tbody>
</table>

### `setupAi({ credits.onCreditsLow })`

The balance just crossed `lowBalanceThreshold` downwards.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the action that settled the spend
    </td>
    
    <td>
      Once per crossing of the threshold downwards; a spend that stays below it is silent
    </td>
    
    <td>
      After the spend settles
    </td>
    
    <td>
      Logged as <code>
        ai.balance_hook_failed
      </code>
      
       and swallowed; the spend stays settled
    </td>
    
    <td>
      None needed: safe to wire straight to a notification
    </td>
  </tr>
</tbody>
</table>

### `setupAi({ credits.onCreditsExhausted })`

The balance just went from positive to zero-or-below.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the action that settled the spend
    </td>
    
    <td>
      Once per crossing from a positive balance to zero or below
    </td>
    
    <td>
      After the spend settles
    </td>
    
    <td>
      Logged as <code>
        ai.balance_hook_failed
      </code>
      
       and swallowed; the spend stays settled
    </td>
    
    <td>
      None needed: safe to wire straight to a notification
    </td>
  </tr>
</tbody>
</table>

### `setupAudit({ onEvent })`

Hear of every event once it is recorded, the package's own and yours: an internal action of yours, by its reference, taking `{ event: vBackendEvent }`.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In an action of its own, scheduled by the transaction that recorded the event, once it commits
    </td>
    
    <td>
      Once per event, fire and forget: nothing retries a run that fails, and the event stays recorded
    </td>
    
    <td>
      Scheduled in the order events are recorded; runs may overlap, so order across events is not kept
    </td>
    
    <td>
      The failure is the action's own, in the deployment's logs; the event and what recorded it stand
    </td>
    
    <td>
      Key what it writes on <code>
        event.id
      </code>
    </td>
  </tr>
</tbody>
</table>

### `access.memberTickets({ enabled })`

Whether the program runs now, for a switch of the app's own (a flag, say): `false` answers `off`, issues nothing, and the links already shared admit nobody (`revoked`) until it is on again.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the query or mutation that reads or mints a member's ticket, and in each code check and sign-up that brings a code or link (nobody signed in), in its transaction
    </td>
    
    <td>
      Once per read, per mint and per code checked; a live read runs it again whenever what it read changes
    </td>
    
    <td>
      A read or a mint asks it after the phase (a public app answers <code>
        open
      </code>
      
       without asking), before the member's ticket; a code check or a sign-up, before the code's row is read
    </td>
    
    <td>
      The read, the mint, the check or the sign-up fails with its error, and nothing is minted or taken
    </td>
    
    <td>
      A read: it may run many times for one member or code, and writes nothing
    </td>
  </tr>
</tbody>
</table>

### `storage.shareable({ canShare })`

Whether the signed-in caller may turn the row's link on or rotate it.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In <code>
        enableShareLink
      </code>
      
      's and <code>
        revokeShareLink
      </code>
      
      's mutations and in <code>
        getShareLink
      </code>
      
      's query, in their transaction, with the signed-in caller as <code>
        ctx.user
      </code>
    </td>
    
    <td>
      Once per <code>
        enableShareLink
      </code>
      
      ; in <code>
        revokeShareLink
      </code>
      
       and <code>
        getShareLink
      </code>
      
       only when the row has a live link and the caller is not the one who shared it. A live <code>
        getShareLink
      </code>
      
       runs it again whenever what it read changes
    </td>
    
    <td>
      <code>
        enableShareLink
      </code>
      
       asks it after the caller is checked (signed in, account present, not banned) and the row is found (a missing row fails <code>
        invalid_input
      </code>
      
       first), before the link is written; <code>
        revokeShareLink
      </code>
      
       after the same caller check and the link read; <code>
        getShareLink
      </code>
      
       after the link read, with only the signed-in identity checked
    </td>
    
    <td>
      <code>
        enableShareLink
      </code>
      
       and <code>
        revokeShareLink
      </code>
      
       fail with its error and change nothing; <code>
        getShareLink
      </code>
      
       reads a throw, a missing row included, as <code>
        false
      </code>
      
       and answers <code>
        null
      </code>
    </td>
    
    <td>
      A check: it may run many times for one row and caller, and writes nothing
    </td>
  </tr>
</tbody>
</table>

### `storage.shareable({ ogImage })`

The storage id of the image the preview card shows, or `null` for none.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In <code>
        resolveShareLink
      </code>
      
      , inside the query or mutation of yours that calls it, once the token matched a live link and its row was found; never from an action
    </td>
    
    <td>
      Once per resolve; a live query that resolves the link runs it again whenever what it read changes
    </td>
    
    <td>
      After the link and its row are read, before the image's expiring URL is signed
    </td>
    
    <td>
      <code>
        resolveShareLink
      </code>
      
       throws, and with it the function of yours that called it
    </td>
    
    <td>
      Synchronous and given only the row: it may run many times for one row, and should read nothing else
    </td>
  </tr>
</tbody>
</table>

### `storage.shareable({ onEnable })`

Runs in `enableShareLink`'s mutation once the link is on, a new one replacing an earlier one included: record an event, tick off a checklist step, stamp the row.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In <code>
        enableShareLink
      </code>
      
      's mutation, in its transaction, with the caller who turned the link on as <code>
        ctx.user
      </code>
    </td>
    
    <td>
      Once per <code>
        enableShareLink
      </code>
      
       that succeeds; each rotation is a call of its own, with <code>
        link.rotated
      </code>
      
       set
    </td>
    
    <td>
      After <code>
        canShare
      </code>
      
       agreed and the new link replaced any earlier one, before the mutation returns the link
    </td>
    
    <td>
      The mutation fails with its error and rolls back with it: no new link, and an earlier one stays live
    </td>
    
    <td>
      Its writes commit with the link or not at all; a conflict reruns the whole mutation, never this hook alone
    </td>
  </tr>
</tbody>
</table>

### `storage.acceptUpload({ check })`

Your check that the upload may go where it is headed, before the content check reads it: the caller's row, room on it, not a file kept already.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the action that calls <code>
        acceptUpload
      </code>
      
      , through the <code>
        ctx
      </code>
      
       your callback closed over (an internal query of yours, a rate limit)
    </td>
    
    <td>
      Once per <code>
        acceptUpload
      </code>
      
      ; a person's retry calls <code>
        acceptUpload
      </code>
      
       again, and with it this
    </td>
    
    <td>
      First, before the content check and <code>
        keep
      </code>
    </td>
    
    <td>
      <code>
        acceptUpload
      </code>
      
       throws its error, and neither the content check nor <code>
        keep
      </code>
      
       runs; an <code>
        invalid_input
      </code>
      
       on <code>
        file
      </code>
      
       or <code>
        images
      </code>
      
      , or a <code>
        quota_exceeded
      </code>
      
      , discards the upload, any other error keeps it for a retry. A check that returns <code>
        false
      </code>
      
       is refused as <code>
        invalid_input
      </code>
      
       on <code>
        file
      </code>
      
      , so the upload is discarded
    </td>
    
    <td>
      A check: it may run again for the same upload, so it should write nothing a second run would trip over
    </td>
  </tr>
</tbody>
</table>

### `storage.acceptUpload({ keep })`

Keep the upload: your internal mutation that claims it with `storage.claim` and writes your row, in one transaction.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      In the action that calls <code>
        acceptUpload
      </code>
      
      , through the <code>
        ctx
      </code>
      
       your callback closed over (<code>
        ctx.runMutation
      </code>
      
       of your mutation)
    </td>
    
    <td>
      Once per <code>
        acceptUpload
      </code>
      
       whose check and content check passed
    </td>
    
    <td>
      Last, after <code>
        check
      </code>
      
       and the content check passed
    </td>
    
    <td>
      <code>
        acceptUpload
      </code>
      
       throws its error; your mutation rolled back, the claim with it, so a refusal of the file (the claim's own <code>
        invalid_input
      </code>
      
       on <code>
        file
      </code>
      
      , the type or the size, or the quota's <code>
        quota_exceeded
      </code>
      
      ) discards the upload, and any other error, an <code>
        invalid_input
      </code>
      
       on a field of yours among them, keeps it for a retry
    </td>
    
    <td>
      Your mutation's transaction: its claim and your row commit together or not at all, and a second keep of a claimed upload is refused <code>
        upload_claimed
      </code>
    </td>
  </tr>
</tbody>
</table>

### `defineJobQueue({ onJobEnd })`

Hear of every job's end: done, failed, stalled, or canceled while it waited or ran, with its id, kind, args, error, run (`retries`) and `endedAt`.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      As its own function, scheduled by the transaction that ended the job, once it commits
    </td>
    
    <td>
      Once per run of a job, whichever way it ended, except a job erased with its owner's account, which ends unheard; a mutation runs exactly once, an action at most once
    </td>
    
    <td>
      After the job's row reads its end; a retried job's runs are heard in turn, <code>
        retries
      </code>
      
       counting up; ends of different jobs run in no set order
    </td>
    
    <td>
      The failure is the hook's own, in the deployment's logs; the job's end and the queue's handling of its credits stand
    </td>
    
    <td>
      An administrator's retry runs a failed job again, and it ends again: compare <code>
        retries
      </code>
      
       with the run you last recorded, and let a later run's end win
    </td>
  </tr>
</tbody>
</table>

### `defineJobQueue({ onOwedCharge })`

Hear how a charge the queue owed ended: a kind charged by output whose `job.charge` the provider refused for a passing reason ends `done` with `owed` on its `onJobEnd`, and the queue tries the charge again in the background.

<table>
<thead>
  <tr>
    <th>
      Runs
    </th>
    
    <th>
      Delivery
    </th>
    
    <th>
      Order
    </th>
    
    <th>
      When it throws
    </th>
    
    <th>
      Idempotency
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      As its own function, scheduled by the transaction that recorded how the charge ended, once it commits
    </td>
    
    <td>
      Once per owed charge that ends, <code>
        charged
      </code>
      
       or <code>
        given_up
      </code>
      
      ; an administrator's retry of a given-up charge owes it again, and it ends again
    </td>
    
    <td>
      After <code>
        onJobEnd
      </code>
      
       was scheduled for the run that owed it, unless the charge landed or was given up while the job still ran, when it may run first; owed charges of different jobs end in no set order
    </td>
    
    <td>
      The failure is the hook's own, in the deployment's logs; the charge's outcome stands
    </td>
    
    <td>
      A retried charge that lands after it gave up is heard <code>
        charged
      </code>
      
       after <code>
        given_up
      </code>
      
      : let the later one win
    </td>
  </tr>
</tbody>
</table>


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
