Video polling, downloading and recovery

Avoid repeated creation of charging tasks and restore long-term generation based on status.

Save task status

Immediately save the gateway task ID, model, creation time and your business task number after successful submission. Poll using the ID returned by the gateway, do not use other numbers from the vendor console, and do not query by someone else’s key.

Polling strategy

Use increment intervals and total deadlines with random jitter. When encountering 429, press Retry-After to wait; when encountering authentication or parameter errors, stop immediately. Reaching the local waiting limit allows the background to continue querying, and the supplier task cannot be directly regarded as canceled.

Create request timeout

When the connection is lost, the task may have been accepted by the upstream. Check the call record or existing task ID before deciding whether to resubmit it. Unless the interface explicitly supports idempotent keys and corresponding semantics, custom request headers do not constitute a guarantee against repeated deductions.

Result Management

Download only in successful state. The error text is sometimes JSON other than 200 and cannot be saved as a video. Establish a domain name policy for the result URL to limit the size and download time; avoid sending the website key to the third-party download host.

Failure reasons, result retention, and retryability depend on the vendor and site configuration. Cost verification is based on call records, and refunds will not be inferred based on local timeout status.

Suggestion state machine

待提交 → 已提交并保存 ID → 排队 / 处理中 → 成功 → 已下载并校验
                                      ↘ 失败 → 记录原因并人工或规则处理

When creating an HTTP timeout, you should enter “Submit results to be verified” and cannot directly return to pending submission. Network abnormality and task failure are different states.

Polling rule example

Start with intervals of a few seconds, gradually lengthen and add jitter, and set upper limits for single requests and entire waits. Priority will be followed when Retry-After is received; if there is no such response header, the application’s own backoff will be used. Different tasks take different times, and the promised completion time is not fixed.

Situation Action
Queuing or processing Save the latest status and query it later
Completed Enter download and content verification
Explicit failure Stop polling, retain reason
401 / 403 Check credentials and attribution, stop intensive retries
429 / Temporary network error Limited backoff
Local wait expires Tag still pending, task ID retained

Persistent fields

Save business task number, gateway ID, model, protocol, status, latest query time and result location. Do not save full keys or infinitely growing response snapshots. After downloading, check the content and update the business status atomically to prevent users from seeing unfinished files.