Issue
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:
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
result from gcloud app logs read
2017-08-26 07:00:05 default[20170823t153316] "GET /crons/example" 301
Solution
Two possibilities, both issues because app engine cron does not follow redirects:
- 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.
Answered By - phynque