Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 527
Brian Leach Avatar asked Apr 05 '18 19:04

Brian Leach


2 Answers

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.

like image 190
syltruong Avatar answered Oct 05 '22 04:10

syltruong


Your urls don't match. Try:

cron:
- description: 'test cron job'
  url: /addit
  schedule: every 1 minutes
like image 33
GAEfan Avatar answered Oct 05 '22 02:10

GAEfan