如何分叉和合并采用 id 列表作为查询参数的 REST API 调用?
我必须调用第三方 GET API,它采用逗号分隔的 id 列表并返回 JSON 响应。 像这样:
def call(sysid)
# RestClient GET https://test.com?ids=sysid.join(',')&....
# parse response and returns
# rescue - any error handling
end
但是 sysid 是一个输入,有时可能有 300 多个元素,并且由于由于 GET 的限制,我的 api 调用出错(可能是因为 URL 长度变得太大)
我如何有效地发送 API 调用(小批量)&将结果合并回来。这样做时: -
- 我应该使用任何 并行
- 如果其中一个批量调用失败,可能会添加重试
- 如果仍然失败,请停止整个过程并重新启动。从 call() 返回错误
- 如果其中一个批量调用失败,可能会添加重试
Ruby 中有针对此类问题的良好模式吗?
I have to call a third party GET API which takes a comma seperated list of ids and returns a JSON response.
Like so:
def call(sysid)
# RestClient GET https://test.com?ids=sysid.join(',')&....
# parse response and returns
# rescue - any error handling
end
But sysid is an input and can sometimes have 300+ elements and due to the limitation of GET, my api call errors out (probably because URL length becomes too big)
How can I efficiently send API calls (in small batches) & merge results back. In doing that:
-
- should I use any Parallelism
- if one of the batch call fails, may be add retries
- if it still fail, stop the whole process & return an error from call()
- if one of the batch call fails, may be add retries
Is there a good pattern in Ruby for this type of problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道好的红宝石模式,但我们可以通过下面的代码
说明
如果状态为 false,您可以返回响应对象或发送特定响应
这是伪代码,但我认为它可能会解决您的问题。
谢谢。
I am not aware of good ruby pattern but we can solve issue by below code
EXPLANATION
you can return response object or send particular response if status is false
This is pseudo code but i think it might solve your problem.
Thank you.