[英]Retry POST request on 202 response - Faraday gem
I need Faraday
to retry my POST request every time when it gets 202 http status as a response. 每当
Faraday
收到202 http状态作为响应时,我都需要Faraday
重试我的POST请求。 I am aware of this module , yet I don't really get how to make use of it, since 202 doesn't throw an error or something and retry_if: block is not called for 202 response. 我知道这个模块 ,但是我并没有真正使用它,因为202不会抛出错误或其他东西,并且retry_if:不会被202响应调用。
I had some success with this middleware but it resends request only once, while 202 response may occur 2 and more times in a row. 我在此中间件上取得了一些成功,但它仅重新发送一次请求,而202响应可能连续发生2次以上。
I wonder if someone could show me a way to do it using retry
module or Faraday middleware. 我想知道是否有人可以向我展示使用
retry
模块或法拉第中间件的方法。
in theory 202 is a success https://httpstatuses.com/202 , it's an acceptance of an asynchronous request, so you really should only have to send your post once, and if you get a 202, you're done your job. 从理论上讲202是成功的https://httpstatuses.com/202 ,它接受了异步请求,因此您实际上只需要发送一次帖子,如果收到202,就可以完成工作。 That link states "There is no facility in HTTP for re-sending a status code from an asynchronous operation."
该链接指出“ HTTP中没有用于从异步操作重新发送状态代码的工具。” So, I think you'd really need to be checking for completion another way.
因此,我认为您确实需要以另一种方式检查完成情况。 However, you could do something like this (just spitballing here):
但是,您可以执行以下操作(只需在此处吐痰):
conn = Faraday.new(url: url, :ssl => {:verify => verify_ssl_cert}) do |faraday|
faraday.adapter Faraday.default_adapter
end
response = conn.get
while response.status == 202
# repeat code above
end
But you run various risks like infinitely looping 但是您会遇到各种风险,例如无限循环
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.