簡體   English   中英

App Engine Cron作業始終返回HTTP狀態代碼301

[英]App Engine Cron Job Always return HTTP status code 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

兩種可能性,兩種都存在,因為App Engine cron不遵循重定向:

  • 默認情況下,Rails是否在路徑中添加斜杠? 我在Django上也遇到了同樣的問題,這就是原因。 我在cron.yaml中更新了路由,以包括尾斜杠(在您的情況下為url: /crons/example/ ),並進行了修復。
  • 您的應用程序是否重定向到https? 如果是這樣,您可能需要免除此路線。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM