为什么这个简单的PUT请求超时?

时间:2015-01-13 18:38:41

标签: ruby-on-rails heroku

def convert_vend_types_param
    if params[:schedule_machine][:vend_types].present?
      vend_types = []
      params[:schedule_machine][:vend_types].each_pair do |vt, active|
        vend_types << vt.to_sym if active.to_i > 0
      end
      params[:schedule_machine][:vend_types] = vend_types
    end
  end

api :PUT, "/v1/schedules/:schedule_id/schedule_machines/:id", "Update a schedule machine"
  param_group :schedule_machine
  error :code => 422
  def update
    convert_vend_types_param

    if params[:schedule_machine]
      if params[:schedule_machine][:products_returned_at]
        new_date = params[:schedule_machine][:products_returned_at]
        if @schedule_machine.products_returned_at == nil || new_date.to_date > @schedule_machine.products_returned_at.to_date
          ScheduleMachineProductCounterJob.new.async.perform(@schedule_machine.id)
        end
      end
    end

    unless @schedule_machine.update_attributes(params[:schedule_machine])
      render(json: { error: 'Invalid schedule machine information' }, status: :unprocessable_entity) and return
    end

    render :show
  end

我的请求和超时:

2015-01-13T17:52:06.437358+00:00 app[web.1]:   Parameters: {"token"=>"mytoken", "schedule_machine"=>{"remove_verified_at"=>"2015-01-13"}, "schedule_id"=>"58", "schedule_location_id"=>"2178", "id"=>"4874"}
2015-01-13T17:52:06.437292+00:00 app[web.1]: Processing by Api::V1::ScheduleMachinesController#update as JSON
2015-01-13T17:52:07.441605+00:00 app[web.1]:   Rendered api/v1/schedule_machines/show.json.rabl (740.3ms)
2015-01-13T17:52:10.681136+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=PUT path="/api/v1/schedules/58/schedule_locations/2178/schedule_machines/4874.json" host=myapp.herokuapp.com request_id=1e4ea64a-8552-4e5d-8580-3c2a8d04ec49 fwd="107.77.72.114" dyno=web.1 connect=2ms service=30001ms status=503 bytes=0

1 个答案:

答案 0 :(得分:0)

Heroku对请求的限制为30秒。您的请求在(service = 30001ms)被杀死,因此方法中的一个步骤就是问题。

看起来你可能有一个数据库超时(可能是因为死机会很奇怪,或者其他阻塞)或者你的异步作业没有像你想象的那样快速返回。

如果您正在使用NewRelic或Skylight,您可以更深入地查看请求以查看内容 继续您也可以从控制台运行命令。