Skip to main content
Backend scripts can schedule other scripts to run in the background after a delay using the queue global. Jobs are stored in Redis and processed by a background worker. This is useful for sending follow-up emails, scheduling reminders, or any task that should happen later without blocking the current request.

queue.push(scriptCode, payload, opts?)

Enqueue a backend script for deferred execution.

Options

Returns: { ok: true, jobId: '...' } on success, or { ok: false, error: '...' } on failure.

How the target script is called

The queued script’s exported function receives the payload object as its only argument:
If you specify opts.fn, a named export is called instead of the default export:

queue.cancel(tag)

Cancel all pending jobs with the given tag for the current brand.
Returns: { ok: true, cancelled: N } where N is the number of jobs removed.

Example: Multi-step abandon email sequence

Queue 3–4 emails spaced over a few days. Cancel the whole sequence on purchase using the shared tag prefix.
Limits per brand:
  • 25,000 pending jobs maximum per brand
  • 64 KB maximum payload size
  • 7-day maximum delay (604,800 seconds)
  • 60-second minimum delay when a non-zero delay is set
  • 5 pushes per script execution
  • 5 cancel calls per script execution
  • 3 retries with exponential backoff on failure
  • Jobs expire after 8 days if not processed
Queued scripts run in a background worker without session or customer context. They have access to cache, queue, and CRM functions, but not request, session, redirect, or response. Design your scripts to receive all needed data in the payload.