APP-45Recommended
Show progress for long actions
When an action takes longer than 10 seconds, run it in the background, show its progress, and let people leave the screen. Tell them when it is done.
How to do it
Start the job and get back a status address, as long-running jobs describes. Show a <progress> element with a count, such as "1,200 of 5,000 rows". Poll every 2 to 5 seconds while the tab is visible. Keep the job list on a page people can return to, and notify them when it ends.
Examples
TypeScript example
const POLL_MS = 3000;
export async function followJob(statusUrl: string, bar: HTMLProgressElement) {
while (true) {
const job = await api.get(statusUrl);
bar.max = job.total;
bar.value = job.done;
if (job.state === 'succeeded' || job.state === 'failed') return job;
await new Promise(done => setTimeout(done, POLL_MS));
}
}
Python example
@app.get("/api/jobs/<job_id>")
def job_status(job_id):
job = jobs.get_for_account(current_user().account_id, job_id)
return {"state": job.state, "done": job.done, "total": job.total, "result": job.result_url}
How to check
A browser test starts an export of 5,000 rows, leaves for another screen and returns. The progress is still shown, and the finished export is listed with a download link.
Sources
Related rules
- AIF-38 Stream long answers in AI features
- API-37 Run long jobs asynchronously in API design
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/app-ui/feedback-and-dialogs/long-action-progress">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.