App Engine Cron作业始终返回HTTP状态代码301

时间:2017-08-26 07:24:10

标签: ruby-on-rails ruby google-app-engine cron

我已按照this guide为我的Rails应用创建了cron作业,但HTTP状态代码始终返回301并且我的作业状态失败。我错过了什么吗?

控制器:

class CronsController < ApplicationController
  def example
    if request.headers["X-Appengine-Cron"]
      Example.do_something
      head :ok
    else
      head :not_found
    end
  end
end

路线:

get 'crons/example', to: 'crons#example'

cron.yaml

cron:
  - description: my cron example
  url: /crons/example
  schedule: every 2 hours from 03:00 to 07:00

来自gcloud app logs read

的结果
2017-08-26 07:00:05 default[20170823t153316]  "GET /crons/example" 301

1 个答案:

答案 0 :(得分:5)

两种可能性,这两个问题都是因为app引擎cron不遵循重定向:

  • 默认情况下,Rails是否会为路由添加尾部斜杠?我和Django有同样的问题,结果证明这是原因。我在cron.yaml中更新了路由以包含尾部斜杠(在您的情况下为url: /crons/example/)并修复了它。
  • 您的申请是否重定向到https?如果是这样,您可能需要免除这条路线。