App Engine Cron作业始终返回HTTP状态代码301 [英] App Engine Cron Job Always return HTTP status code 301
本文介绍了App Engine Cron作业始终返回HTTP状态代码301的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已遵循本指南为我的Rails应用程序创建cron作业,但是HTTP状态代码始终返回301,而我的作业状态失败。我是否缺少某些东西?
I have followed this guide to create cron job for my Rails app, but the HTTP status code is always returns 301 and my job status is failed. Am I missing something?
controller:
controller:
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.yaml
cron:
- description: my cron example
url: /crons/example
schedule: every 2 hours from 03:00 to 07:00
从 gcloud应用程序日志读取的结果
2017-08-26 07:00:05 default[20170823t153316] "GET /crons/example" 301
推荐答案
两种可能性,两种都存在,因为应用引擎cron不遵循重定向:
Two possibilities, both issues because app engine cron does not follow redirects:
- Does Rails默认添加尾部斜线到路由?我在Django上也遇到了同样的问题,这就是原因。我在cron.yaml中更新了路由,以包括尾斜杠(在您的情况下为
url:/ crons / example /
),并进行了修复。 - 您的应用程序是否重定向到https?如果是这样,您可能需要免除此路线。
- Does Rails add trailing slashes to routes by default? I had the same issue with Django and this turned out to be the cause. I updated the route in cron.yaml to include the trailing slash (in your case
url: /crons/example/
) and that fixed it. - Is your application redirecting to https? If so, you may need to exempt this route.
这篇关于App Engine Cron作业始终返回HTTP状态代码301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文