GCP CRON jobs failing with no logs
Asked Answered
C

3

6

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
Consumedly answered 5/4, 2018 at 19:25 Comment(5)
I have replicated the situation by adding a cron job to my application similar to the one described here, and I can see the logs after the cron jobs finish. I would like to confirm if you have set any firewall rules or log exclusions defined, so that access to your app is limited to particular IP addresses or logs related to cron jobs are being excluded.Emmons
Are you using a dispatch file?Parshall
I am not using a dispatch fileConsumedly
Having the same issue... Vanilla Flask and flexible envUnplaced
Having same issue, no firewall rulesUnderstrapper
S
5

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.

Sophistic answered 3/8, 2018 at 10:0 Comment(0)
E
2

Your urls don't match. Try:

cron:
- description: 'test cron job'
  url: /addit
  schedule: every 1 minutes
Exempt answered 5/4, 2018 at 20:4 Comment(1)
They do match, I left out the blueprint stuff. I will edit to avoid confusionConsumedly
D
0

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://mcmap.net/q/1776192/-error-302-running-cron-and-login-admin-in-app-yaml-in-google-app-engine and comments that lead me to the solution.

Delphinium answered 25/10, 2020 at 3:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.