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

kun*_*aji 0 ruby cron google-app-engine ruby-on-rails

我已按照本指南为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
Run Code Online (Sandbox Code Playgroud)

路线:

get 'crons/example', to: 'crons#example'
Run Code Online (Sandbox Code Playgroud)

cron.yaml

cron:
  - description: my cron example
  url: /crons/example
  schedule: every 2 hours from 03:00 to 07:00
Run Code Online (Sandbox Code Playgroud)

产生于 gcloud app logs read

2017-08-26 07:00:05 default[20170823t153316]  "GET /crons/example" 301
Run Code Online (Sandbox Code Playgroud)

小智 6

两种可能性,两种都存在,因为App Engine cron不遵循重定向:

  • 默认情况下,Rails是否在路径中添加斜杠?我在Django上也遇到了同样的问题,这就是原因。我在cron.yaml中更新了路由,以包括结尾的斜杠(在您的情况下url: /crons/example/),并进行了修复。
  • 您的应用程序是否重定向到https?如果是这样,您可能需要免除此路线。