简体   繁体   English

当进程运行时请求被拒绝时,我应该返回什么 http 代码?

[英]What http code should I return when the request is rejected while process is running?

I have a REST api that launch a heavy calculation on the serveur (it tikes a few seconds).我有一个 REST api,可以在服务器上启动大量计算(需要几秒钟)。 For that I'm returning 202 (ACCEPTED) http code to the client, which will not expect a returning value.为此,我将向客户端返回 202 (ACCEPTED) http 代码,该代码不会期望返回值。 Ok so far.到目前为止还好。

What will I return for another client how calls this url while the process (launched by the first call) is not terminated ?当进程(由第一次调用启动)未终止时,我将为另一个客户端返回什么?

This second call will not be processed, it will be ignored and the client must try again later .第二次调用将不会被处理,它将被忽略,客户端必须稍后再试

If you insist on the current behavior, then you'll return 503 .如果您坚持当前的行为,那么您将返回503 This tells the (standard compliant) client that your server is temporarily overloaded, and it can retry later (you can even hint when it can on Retry-After header. While standard-compliant, you'll only want to do this if queuing the process requested by the second call later is impossible, perhaps because the internal state will have changed so the second call is invalid. If it's possible to just queue the process with an identical result as when the client manually retry the call, then just return 202.这告诉(符合标准的)客户端您的服务器暂时过载,它可以稍后重试(您甚至可以在Retry-After标头上提示何时可以。虽然符合标准,但您只希望在排队时执行此操作)之后第二次调用请求的进程是不可能的,可能是因为内部状态会改变,所以第二次调用是无效的。如果可以将进程与客户端手动重试调用时相同的结果排入队列,那么只需返回 202 .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该对可能返回陈旧数据的GET请求使用什么HTTP状态代码? - What HTTP status code should I use for a GET request that may return stale data? 没有创建资源时,我应该为POST返回什么HTTP状态代码? - What HTTP status code should I return for POST when no resource is created? 我应该返回什么 HTTP 状态响应码? - What HTTP status response code should I return? 如果没有可用数据,应该返回什么http - What http return code should be if no data available 没有数据时应返回哪个http代码 - Which http code should return when there is no data 尝试创建超出最大限制的资源时,POST API请求的适当http状态代码应该是什么 - what should be the appropriate http status code for POST API request when trying to create resources beyond maximum limit 当请求正确但没有特定用户的数据时,我们应该返回什么状态码? - What status code we should return when request is correct but there is no data for the specific user? 我应该返回什么响应状态代码? - What response status code should I return? 如果由于某些业务逻辑目前无法满足客户端请求,服务器应该返回什么 HTTP 状态代码? - What HTTP status code should server return if client request can't be fulfilled at the moment because of some business logic? 我应该何时从REST应用程序向客户端返回HTTP状态码500(内部服务器错误)? - When should I return HTTP Status Code 500 (Internal Server Error) from REST application to client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM