Claude Templates / A-tier · High leverage
Infrastructure
The Trigger.dev Worker Playbook
The three-file pattern for anything that can't finish inside an HTTP request.
TRIGGER-DEV-WORKER-PLAYBOOK.md · 12 sections · 2,590 words · 21 KB · markdown
Any task that can exceed 60 seconds has to leave the request cycle. This is the pattern for doing it without losing work: a worker, a dispatch route, and a bridge — plus orphan recovery, refund-on-failure, and mount-time resume so a closed browser tab doesn't strand a job.
What's inside
- //The three-file pattern (worker + dispatch + bridge) with full code
- //Refund-on-failure so a crashed job doesn't eat a user's credits
- //Orphan recovery for jobs whose callback never landed
- //Mount-time resume — the UI reattaches to an in-flight job
- //Deploy discipline: when a Vercel push also needs a worker redeploy
When to use it
The moment a task can exceed 60 seconds.
Build these first
Unlocks
Straight from the file
Browser-bound generation paths and /api/generate-style routes that await long providers are banned. Tab close mid-render orphans the pipeline row, burns credit, and silently corrupts state. The pattern below eliminates that entire class of bug.
Table of contents
- 0. The universal rule
- 1. Use this spec
- 2. Architecture
- 3. The three-file pattern
- 4. Worker self-heal (Vara incident pattern)
- 5. Generic status endpoint — [/api/jobs/[runId]/route.ts](file:///<reference-app>/src/app/api/jobs/[runId]/route.ts)
- 6. trigger.config.ts — build extensions
- 7. Mount-time orphan recovery (pipeline page wiring)
- 8. Auto-deploy rule (mandatory)
- 9. The audit-orphan-charges cron (final safety net)
- 10. Common pitfalls
- 11. Kickoff prompt
How to run it
Drop TRIGGER-DEV-WORKER-PLAYBOOK.md into your repo, then tell Claude Code: “Read TRIGGER-DEV-WORKER-PLAYBOOK.md and implement it in this codebase.” It's written for an agent to execute end to end. Search the file for angle-bracket placeholders and swap in your own project names, domains, and keys before the first run.
More infrastructure playbooks
Email Infrastructure
Postmark, the SPF/DKIM/DMARC recipe, drip campaigns, and transactional vs marketing routing.
Read + download →B-tierWebhook Receiver
Receiving third-party webhooks — and sending your own — without losing events.
Read + download →B-tierScheduler Engine
One queue for every future-dated action — drips, reminders, scheduled sends.
Read + download →