{"success":true,"name":"give-every-node-js-background-job-an-owner-a-retry-and-a-dea","description":"Adding cron tasks, queues, or fire-and-forget work in Node.js.","category":"ai-brimind","path":"ai-brimind/give-every-node-js-background-job-an-owner-a-retry-and-a-dea/SKILL.md","file":"SKILL.md","content":"---\nname: give-every-node-js-background-job-an-owner-a-retry-and-a-dea\ndescription: \"Adding cron tasks, queues, or fire-and-forget work in Node.js.\"\n---\n\n# Give Every Node.js Background Job an Owner, a Retry, and a Dead End\n\n## When to use\nProject is Node.js, and you are adding scheduled tasks, queue consumers, emails, or any work that runs outside a request.\n\n## Example request\nSending email with a floating promise inside the handler → failures vanish silently; a job queue (BullMQ) with retries owns async work. setInterval as a production scheduler → skips on restarts, doubles on two instances — real schedulers or queue-based repeat jobs handle this. A job that retries forever on a poison message → blocks the queue; retry caps plus a dead-letter destination is the pattern. No record of whether last night's job ran → jobs need logging and status like requests do.\n\n## Instructions\nAct as a Node.js developer who treats background work as production traffic that just doesn't have a user waiting. Never fire-and-forget: any work triggered outside the response cycle (emails, syncs, cleanups) goes through an existing job system (BullMQ or the platform's scheduler) — not floating promises and not bare setInterval, which double-runs with two instances and silently skips across restarts. For every job, define three things explicitly: (1) idempotency — the job WILL run twice eventually; running it twice must be safe, say why; (2) a retry policy with backoff AND a maximum attempt count, after which the job lands in a dead-letter destination for inspection instead of retrying forever and blocking the queue; (3) observability — each run logs start, outcome, and duration, so 'did last night's job run?' has an answer in the logs, not a shrug. Check what the hosting platform already provides (cron services, queue offerings) before building scheduling yourself. Only ship the job once all three are confirmed, and explain what happens on the worst path: the job that fails every single attempt.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1000\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}