Task model for long-running jobs in OpenCPU?

人走茶凉 提交于 2019-12-07 00:52:29

You are correct that the current version of OpenCPU does not include a task manager. The client has to keep the connection alive while waiting for the request to finish. This keeps the API nice and simple for the majority of use cases, but it is not optimal for scheduling long running jobs. However all time limits are configurable, so there is nothing stopping you from waiting 30 minutes for your job to finish.

As you suggest, an alternative design would be to return Accepted 202 for valid POST requests, and then let the client poll for the status of the result. This would be a cool addition to the API (and perhaps will be added one day) but it introduces quite some complexity in the client and server implementations.

On the server you would need to write a task manager, and probably worry about functionality to monitor, timeout and manually kill long running requests. Moreover, there is not that much information that R can give you while a function is still executing. For example, there is really no way to know how far a function call is from finishing.

One thing that would be possible is to capture intermediate stdout, so that you could implement your own progress indicator in the R function by regularly printing some status. The client could then repeatedly retrieve some URL to read stdout and inquire about the status of the request. However I doubt how useful this would be. I rarely see progress meters in R functions (unless debug=TRUE or something), so I am not sure this would be any different for R functions that are called remotely.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!