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:
| Configuration | Purpose |
|---|---|
INNGEST_EVENT_KEY | Send production events |
INNGEST_SIGNING_KEY | Verify /api/inngest requests |
src/adapters/jobs/inngest | Client, handler, and function implementation |
src/app/api/inngest/route.ts | Inngest 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:
| Endpoint | Purpose | Suggested cadence |
|---|---|---|
/api/jobs/operations/snapshot | Persist the current dashboard as a daily snapshot | Once per day |
/api/jobs/operations/alerts | Evaluate rules and send de-duplicated notifications | Every 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