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



我已经按照本指南为我的 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

两种可能性,两个问题,因为应用引擎 cron 不遵循重定向:

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

相关内容

最新更新