Brian Leach
Brian Leach

Reputation: 4154

GCP CRON jobs failing with no logs

I am trying to set up a CRON job in a Google Cloud Platform. The job is showing up in the GCP console, although it is failing. There are no logs that reveal why it is failing. The schedule seems to be working ok, and I am able to manually run the job, although it also fails when initiated manually.

If I go to http://...../api/status/addit in the url bar, the job runs as expected.

There is a link to "View Logs" in on the task queues page where it shows my CRON job, but when I go to those logs they are completely empty.

Looking at the nginx request logs does not show any requests made to that url (or any requests for that matter). If I go to the url for the job manually, I can see those requests show up in the logs and everything that is supposed to happen happens so I know that endpoint is good.

Google App Engine Flexible environment, Python 3

Flask API

What other info can I provide? There are so many moving parts that I don't want to flood the question with irrelevant info.

cron.yaml:

cron:
- description: 'test cron job'
  url: /api/status/addit
  schedule: every 1 minutes

endpoint:

< some Flask Blueprint stuff initiates the "status" blueprint so that this url will resolve to /api/status/addit >
...

@status.route('/addit')
def add_to_file():
    print('made it into the request')
    from flask import Response
    res = Response("{'foo':'bar'}", status=202, mimetype='application/json')
    return res

Upvotes: 6

Views: 2651

Answers (3)

TimSC
TimSC

Reputation: 1539

I ran into a similar problem when I was using SSL and a script to redirect users from http to https URLs (in my case SSLify). Google app cron seems to use the http version (at least for my flex app), so when my app was called by cron, it returned a 302 redirect to the https version which was interpreted as an error.

"A cron job will invoke a URL, using an HTTP GET" https://cloud.google.com/appengine/docs/flexible/nodejs/scheduling-jobs-with-cron-yaml

Thanks to https://stackoverflow.com/a/53018498/4288232 and comments that lead me to the solution.

Upvotes: 0

syltruong
syltruong

Reputation: 2723

I experienced the same issue with the same kind of configuration (GAE flexible, Python 3):

Cron fails with no logging.


Turns out it is a firewall issue: my default action was set to DENY.

According to the docs:

Note: If you define a firewall in the flexible environment, you must set firewall rules for both the 10.0.0.1 and 0.1.0.1 IP addresses to allow your app to receive requests from the Cron service.

Whitelisting 10.0.0.1 and 0.1.0.1 solved my issue.

Upvotes: 5

GAEfan
GAEfan

Reputation: 11360

Your urls don't match. Try:

cron:
- description: 'test cron job'
  url: /addit
  schedule: every 1 minutes

Upvotes: 2

Related Questions