简体   繁体   English

如果请求时间太长,Rails 200状态代码将更改为302?

[英]Rails 200 status codes change to 302 if a request takes too long?

I have a rails app that fires off some code to assemble a large report on all a users data. 我有一个Rails应用,该应用会触发一些代码以针对所有用户数据组装一个大型报告。 This takes ages and needs to come off an external API (salesforce). 这需要很长时间,并且需要使用外部API(salesforce)。

I have code that works on many records: 我有适用于许多记录的代码:

  • Grabbing the data 抓取数据
  • Formatting it correctly 正确格式化
  • Passing it to the view and rendering as a pdf before refreshing the page with ajax. 将其传递给视图并以pdf形式呈现,然后再使用ajax刷新页面。

Most requests end like this: 大多数请求都这样结束:

Rendered record_requests/_get_digest.html.erb (2974.9ms) Rendered record_requests/get_digest.js.erb (2983.4ms) Completed 200 OK in 5957ms (Views: 2770.9ms | ActiveRecord: 222.1ms)

Which is great! 太好了!

But some of the largest records can take 6+ minutes to grab and process - at which point something different occurs: ``` 但是一些最大的记录可能需要6分钟以上的时间来处理-在这时发生了一些不同的事情:

Redirected to https://[base_URL]/record_requests/5 Completed 302 Found in 288345ms (ActiveRecord: 2.4ms) This is also a disaster because the redirect seems to kick off the initial request again so i get stuck in a loop... Redirected to https://[base_URL]/record_requests/5 Completed 302 Found in 288345ms (ActiveRecord: 2.4ms)这也很Redirected to https://[base_URL]/record_requests/5 Completed 302 Found in 288345ms (ActiveRecord: 2.4ms)因为重定向似乎再次启动了初始请求,因此我陷入了循环...

These two requests use exactly the same code!! 这两个请求使用完全相同的代码! Why is one getting rendered and the other getting redirected? 为什么一个被渲染而另一个被重定向? Is there a built-in rails timeouts. 是否有内置的Rails超时。

Soo confused, can anyone shed any light on this? 太困惑了,有人能对此有所解释吗?

This all works via the very excellent Restforce gem,the full gemfile is listed here . 所有这一切都通过非常出色的Restforce gem进行, 此处列出了完整的gemfile。

The controller looks like this: 控制器如下所示:

# GET /record_requests/1 def show respond_to do |format| format.html {} # format.json { head :ok } format.js end end

# GET /record_requests/1/get_record def get_digest @client = @record_request.client_digest @request_digest = @record_request.build_request_digest respond_to do |format| format.js end end

If its pretty much exactly 600s it will be a timeout. 如果恰好是600秒,那将是超时。

I would guess, possible sources are: 我猜,可能的来源是:

  • salesforce itself, althought I can't see a mention of a specific timeout for requests salesforce本身,尽管我看不到请求的特定超时
  • the client library you use to call the api, and how you handle the reponse 用于调用api的客户端库以及如何处理响应
  • the webserver you host on 您托管的网络服务器

Of the three, as it's rails showing the redirect - I would guess it's the second one, but without the details of the code and library you use, it's hard to say - it depends on how you handle errors in that method. 在这三个中,由于它显示了重定向,所以我想这是第二个,但是由于没有使用的代码和库的详细信息,因此很难说-它取决于如何处理该方法中的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM