为持久任务创建REST API的最佳方法? [英] Best way to create REST API for long lasting tasks?

查看:69
本文介绍了为持久任务创建REST API的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有2台服务器.

Suppose I have 2 servers.

第一个是提供某些计算的服务,该计算可能会持续很长时间(几分钟到几小时).

The first is a service that provides some computations, which can last long time (minutes to hours).

第二台服务器将使用此服务来计算一些数据.

The second server will use this service to have some data computed.

到目前为止,我正在尝试为第一台服务器设计REST API.但是我想听听一些关于在完成长期任务后如何为通知建模的意见.

I'm trying to design a REST API for the first server and so far so good. But I'd like to hear some opinion on how to model notifications when the long lasting task is finished.

到目前为止,我考虑了2种方法:

I considered 2 approaches so far:

  1. 轮询-第二台服务器会不时询问结果.
  2. 回叫-完成后,第二个服务器将为第一个要呼叫的用户设置一个uri.但这在REST API中有点味道.

你怎么看?

推荐答案

除了我已经已经回答的内容这个类似的问题中,我建议使用Atom发布协议进行通知(您可以将其发布到第二台服务器)

In addition to what I've already answered in this similar question, I'd suggest using the Atom Publishing Protocol for the notification (you could publish to your second server).

这篇关于为持久任务创建REST API的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆