Resources · 107

Asynchronous API jobs: track status, resume and cancel

Separate accepted requests, started processing and final outcomes of long-running operations.

· 3 min

Laptop displaying code on a desk Illustration · fictional scene

What this guide helps achieve

  • Define states
  • Protect tracking
  • Bound status queries
  • Test concurrent cancellation
  • Handle abandoned work
  • Define repeat and expiry contracts

Quick check

  • Does 202 mean the job is finished?
  • Does cancellation erase every effect?
  • Should status queries continue indefinitely?

Step-by-step method

  1. 01

    Define states

    Describe received, queued, active, completed, failed and cancellation requested. A 202 response does not prove success; define how the client obtains the final outcome.

    Deliverable: transitions and authoritative outcome.

  2. 02

    Protect tracking

    Associate each identifier with account and request scope. Check rights for status, results and cancellation; an unguessable identifier does not replace authorisation.

    Deliverable: cross-account tests.

  3. 03

    Bound status queries

    Set polling frequency and duration, terminal state and result expiry. Preserve a reference allowing resumption after browser closure without restarting processing.

    Deliverable: tracking and resumption policy.

  4. 04

    Test concurrent cancellation

    Simulate cancellation while queued, running and publishing results. Define what can still be stopped and which effects remain; confirm an actually observed outcome.

    Deliverable: race conditions and remaining effects.

  5. 05

    Handle abandoned work

    Identify stalled jobs, repeated errors and expired results. Assign recovery, closure or review; do not present estimated progress as proof of completion.

    Deliverable: orphan-job monitoring.

  6. 06

    Define repeat and expiry contracts

    Decide whether another submission can recover the existing job. If a repeat key is used, define its account scope, lifetime, associated parameters and conflict behavior. Test acceptance with a lost response. Separate status expiry from result deletion: an unavailable result does not prove that processing never happened.

    Deliverable: repeat, expiry and incident-follow-up contract.

Choose next steps using confirmed state

Check the observed state before choosing next steps.

  1. Queued or active

    Resume tracking with the same reference.

  2. Cancellation requested

    Check outcome and effects already produced.

  3. Terminal state

    Check result, rights and retention period.

Prepare recovery without inventing success

Fictional cases to adapt to your service contract. Expected results are acceptance criteria to test, not customer outcomes.

SituationAction to prepareExpected evidence
The acceptance response is lostRecover the job through the documented repeat mechanism or check the request before creating another.Retained identifier, contract scope and job count in the test.
The client stops polling at its maximum durationRetain a tracking-interrupted state and a recovery path; do not announce business failure without evidence.Server state distinct from client timeout and recovery using the same reference.
Cancellation arrives while the result is being publishedConfirm the observed outcome and reconcile effects; requesting a stop is not erasure.Timeline, final state and proportionate list of remaining effects.
The result expires before the person returnsExplain expiry and apply the authorized recovery or new-request rule.Documented retention, denied out-of-scope access and no silent restart.

Reusable worksheet

Complete with your authorised observations. These fields are a working template, not observed results.

FieldInformation to record
ReferenceAccount, operation and identifier
StateTransition, time and source
OutcomeResult, error or remaining effects
AcceptanceSame job recovered, rights checked and outcome or uncertainty explained

Worked example

Illustrative situation

Illustrative case: an export is accepted and the browser closes. A later session finds the ongoing job.

Decision and expected evidence

Reuse the identifier, verify result access rights and offer cancellation with confirmed status.

Distinguish the mechanisms

MechanismPurposeCheck or limitation
AcceptedRequest received for processingNot final success
Cancellation requestedIntention to stopConfirm actual outcome
CompletedResult availableCheck rights and retention

Management indicators

IndicatorWhat it measuresFirst action
Orphan jobsJobs without qualified progressAssign recovery or closure
ResumptionCases resumed without duplicationCorrect unnecessary restarts

Common pitfalls

  • Present acceptance as final success
  • Authorise results using only a job identifier
  • Poll without bounded frequency or duration

Frequently asked questions

Does 202 mean the job is finished?

No. Processing is not necessarily complete. The client needs access to an authoritative outcome.

Does cancellation erase every effect?

Not always. Some effects may already exist; specify them and how they are reconciled.

Should status queries continue indefinitely?

No. Define an appropriate frequency and duration, use the delay indication provided by the service and stop at a terminal outcome. A client-side timeout does not turn an active job into server-side failure.

Official references

References consulted: . The method and worksheet propose checks to adapt to your context; they do not constitute certification.