Agent Wranglers

API-37Recommended

Run long jobs asynchronously

When work can take longer than 10 seconds, accept it with 202 and a status resource the client can poll.

How to do it

Return 202 with a Location header pointing to a job, such as /jobs/job_31c. The job shows its state, such as queued, running, succeeded or failed. When done, it links to the result or holds a problem details object. Send Retry-After on the job to pace polling.

Examples

HTTP example

POST /exports HTTP/1.1

HTTP/1.1 202 Accepted
Location: /jobs/job_31c
Retry-After: 5

How to check

Start an export in a test. The answer is 202 with Location, and polling ends in a completed state with a result link.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/reliability/long-running-jobs">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.