Retry

Schedules failed background tasks for automatic retry, with configurable attempt limits and exponential backoff. Admins can inspect pending tasks and attempt history.

  • TypeScript
npm i @spacetimedb/retry

A durable task-retry system that lives inside a SpacetimeDB server module, letting you schedule background work, automatically re-run it with increasing delays when it fails, and inspect pending tasks and attempt history through admin views.

  • Transactional email delivery: Sending a receipt or notification after a purchase where a temporary downstream failure should not silently drop the message.
  • External API calls: Calling a third-party service from a reducer where the service may be temporarily unavailable and the call needs to be retried a bounded number of times.
  • Eventual consistency across systems: Propagating a state change to an external data store where the write might fail and must be retried without duplicating side effects.
  • Admin-monitored background jobs: Any background work where operators need visibility into what is queued and what has failed, without building a custom audit log.
  • User-initiated async operations: Handling requests where the caller should not wait for completion but the work must eventually succeed or be explicitly abandoned.

When a task is submitted, it is stored with its arguments, a maximum attempt count, and a base delay. The first attempt runs immediately. If the handler signals failure or throws an unexpected error, the task is rescheduled with a delay that doubles on each subsequent attempt. This continues until the handler succeeds or the attempt limit is reached.

Handlers are expected to be safe to run more than once for the same input. Each attempt runs inside the module's normal transaction model, so any writes the handler makes before a failure are committed as part of that attempt. If a task's arguments are fundamentally invalid, the handler can signal that explicitly, which permanently stops retries for that task without consuming the remaining attempt budget.

A rolling history of the most recent attempts is kept and exposed through admin-only views, alongside a list of tasks still waiting to run. Access to submit tasks directly or manage administrators is controlled by an identity-based admin list that is seeded when the module is first initialized.

Related submodules

Authz

Roles, scopes and grants for multi-user modules: wildcard permissions, role inheritance, scope trees, expiring grants, invite links, an audit log and row-level security, with no privilege escalation.

Lethalchip0/wkCommunity

Cron

Schedules recurring tasks in a SpacetimeDB module using calendar expressions or fixed intervals. Supports time zones, per-job arguments, failure limits, and runtime schedule changes.

SpacetimeDB0/wk

Crypto

Hashing, encoding conversion, and webhook signature verification for Stripe, Svix, and GitHub. Includes timing-safe byte comparison and hex/base64 helpers.

SpacetimeDB0/wk
Submodule

Edit details

One short paragraph describing the submodule.

A few bullets for scenarios where this is a good fit.

A few short paragraphs at the conceptual level.