Background Jobs

Background Jobs

The generator supports Inngest and Cloudflare Workflows. Product code sends work through jobService; the selected adapter owns event format and runtime.

Inngest

Use Inngest on Server, Docker, or Vercel:

ConfigurationPurpose
INNGEST_EVENT_KEYSend production events
INNGEST_SIGNING_KEYVerify /api/inngest requests
src/adapters/jobs/inngestClient, handler, and function implementation
src/app/api/inngest/route.tsInngest callback

Run the Inngest Dev Server separately when inspecting or triggering local functions.

Cloudflare Workflows

The Cloudflare target calls a Workflow through the NEXTDEVTPL_WORKFLOW binding. Generated wrangler.jsonc declares its binding, workflow name, and class. Create the resource, check names before deployment, and let request context inject the binding lazily at runtime.

Cron

Credit expiry uses /api/jobs/credits/expire, protected by CRON_SECRET. The Vercel target emits cron configuration when the module is selected; use the platform scheduler to call the same endpoint elsewhere.

When operations is selected, schedule these protected endpoints with the same Authorization: Bearer <CRON_SECRET> header:

EndpointPurposeSuggested cadence
/api/jobs/operations/snapshotPersist the current dashboard as a daily snapshotOnce per day
/api/jobs/operations/alertsEvaluate rules and send de-duplicated notificationsEvery 5-15 minutes

The operations endpoints are safe to run more than once for the same period. They report query or delivery failures without making the original product request fail. The Vercel config currently emits the credit-expiry cron only, so add operations schedules explicitly in the platform dashboard.

Job rules

  • Keep work idempotent so duplicate events do not double-charge, grant, or notify.
  • Persist state required for retries in the database or workflow state.
  • Log job and external event IDs while filtering secrets and sensitive content.
  • Split long work into retryable steps and add timeouts to external calls.

After changes:

pnpm test:run -- src/test/jobs
pnpm test:run -- src/test/adapters/cloudflare.test.ts

On this page