方法与执行时间长REST请求

方法与执行时间长REST请求

本文介绍了方法与执行时间长REST请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个REST服务,将需要大约5分钟来执行。它将由一个内部应用程序只叫了几声一天。是否有使用REST的问题(如:HTTP)请求需要5分钟才能完成?

We are building a REST service that will take about 5 minutes to execute. It will be only called a few times a day by an internal app. Is there an issue using a REST (ie: HTTP) request that takes 5 minutes to complete?

难道我们不用担心超时?我们应该开始在服务器上的一个单独的线程请求和对状态的客户调查?

Do we have to worry about timeouts? Should we be starting the request in a separate thread on the server and have the client poll for the status?

推荐答案

假设你可以HTTP超时使用你选择的框架配置,那么你可以通过一个GET请求只是挂5分钟。

Assuming that you can configure HTTP timeouts using whatever framework you choose, then you could request via a GET and just hang for 5 mins.

但它可能是更灵活的通过POST开始执行,拿到收据(数字/ ID等等),然后使用5分钟后(也许重试给你的程序将不会执行GET正是每次5分钟)。如果请求仍在进行中,然后返回相应的HTTP错误code(404也许是的,但你会返回一个不存在收到GET),或返回的结果(如果可用)。

However it may be more flexible to initiate an execution via a POST, get a receipt (a number/id whatever), and then perform a GET using that 5 mins later (and perhaps retry given that your procedure won't take exactly 5 mins every time). If the request is still ongoing then return an appropriate HTTP error code (404 perhaps, but what would you return for a GET with a non-existant receipt?), or return the results if available.

这篇关于方法与执行时间长REST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:11