我已关注本指南 https://cloud.google.com/appengine/docs/flexible/ruby/scheduling-jobs-with-cron-yaml为我的 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
routes:
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?如果是这样,您可能需要豁免此路线。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)