我调用一个异步服务,它需要大约80秒的时间来响应。我跑:
curl -v -X POST https://hostname.com/service/v2/predict \
-H 'x-api-key: somekey' \
-H 'x-request-id: longfiles' \
-H "Authorization: Bearer dfv651df8fdvd" \
-H 'Prefer: respond-async, wait=200' \
-F 'contentAnalyzerRequests={"inputtest": "this is a test"}
-F infile=@/mnt/file/stream-01865caa-b2e0-40e4-b298-1502fcc65045.json
该命令指定wait=200
,但curl在60秒内返回。因为服务需要80秒才能响应,所以我没有得到响应(但是如果我使用wait=1000
,我确实会得到响应)。为什么?
用-v
输出curl查询:
> Prefer: respond-async, wait=200
> Content-Length: 19271573
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------5873f0b92dd68547
>
< HTTP/1.1 100 Continue
< HTTP/1.1 202 Accepted
< Server: openresty
< Date: Fri, 07 Oct 2022 21:55:33 GMT
< Content-Length: 0
< Connection: keep-alive
< x-request-id: longfiles
< vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers
< location: https://hostname.com/service/v2/status/longfiles
< retry-after: 1
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Authorization,Content-Type,X-Api-Key,User-Agent,If-Modified-Since,Prefer,location,x-transaction-id,retry-after,cache-control
< Access-Control-Allow-Methods: GET, POST, PUT ,DELETE, OPTIONS,PATCH
< Access-Control-Expose-Headers: location, retry-after, x-request-id, x-transaction-id, cache-control
< Access-Control-Max-Age: 86400
<
* Connection #0 to host hostname.com left intact
发布于 2022-10-08 06:36:44
请求已被接受用于处理的HTTP HTTP/1.1 202 Accepted
表示,但处理尚未完成。
关键是:
< location: https://hostname.com/service/v2/status/longfiles
< retry-after: 1
这意味着一旦处理完成,输出将在https://hostname.com/service/v2/status/longfiles上可用。retry-after: 1
意味着人们可以以每秒最多1次的速度重试查看该位置。
该命令指定wait=200,但curl在60秒内返回。
服务可能有60秒的超时时间来发送HTTP 202 Accepted
响应。
呼叫计划的流程图:
https://unix.stackexchange.com/questions/720205
复制相似问题