2017-08-26 45 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