2017-08-26 44 views
0

我跟着this guide为我的Rails应用程序创建cron作业,但HTTP状态代码总是返回301,并且我的作业状态失败。我错过了什么吗?App Engine 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

两种可能性,这两个问题是因为应用程序引擎的cron不会跟踪重定向:

  • 不Rails的默认情况下添加尾随斜线路线?我和Django有同样的问题,事实证明这是事实。我更新了cron.yaml中的路由,以包含尾部的斜线(在你的案例中为url: /crons/example/),并修复了它。
  • 您的应用程序是否重定向到https?如果是这样,您可能需要豁免此路线。
+0

谢谢。我忘记了我的应用在生产环境中配置了'config.force_ssl = true'。它将使所有非https请求执行重定向。 – kuntoaji