c/backend › command
0votes

Add a background job safely

Workflow
submitted by CommandVault editors to c/backend

Move slow work out of the request with retries and idempotency.

Workflow · 3 variables
The request handler below does slow work ({{slow_work}}) inline:

{{code}}

Refactor it to a background job using {{queue_tool}}:
1. The handler validates input, enqueues a job with an idempotency key, and returns 202 immediately.
2. The worker is safe to run twice for the same key.
3. Retries use exponential backoff with a max attempt count; failures land in a dead-letter list.
4. Log job id, attempt and duration; never log secrets or full payloads.
5. Show how the UI can poll or subscribe for the result.

Return the new handler, the worker and a short runbook for stuck jobs.
0 commentsreport

Try it here

Fill in {{slow_work}}, {{code}}, {{queue_tool}} above first for a better answer, or run it as is and the AI will assume sensible values.

or open in ChatGPT · Claude · Perplexity

How to use this prompt

  1. Fill in the 3 blanks above. The more specific you are, the better the answer.
  2. Copy it and paste it into ChatGPT, Claude, Gemini, Cursor or Codex, or use "Try it here" for a quick test.
  3. Read the answer critically: check anything it claims about your code or data before you rely on it.
  4. Careful: this one is marked medium risk. Review what the AI suggests before you run it on real systems or data.
  • {{slow_work}} Slow work
  • {{code}} Code
  • {{queue_tool}} Queue tool

More from c/backend

See all of c/backend →
0 comments

Log in to join the discussion.