Ain Tohvri
Ain Tohvri

Reputation: 3035

How to debug Cron Jobs on Google App Engine?

Situation

Cron is (alongside the Rails app), deployed to GCP with cron.yaml:

cron:
- description: count things regularly
  url: /api/v1/cron/rake_task
  schedule: every 30 minutes
  timezone: Europe/Berlin

Problem

enter image description here

Question

How to see the cron log? View reveals nothing at all, but clearly there has to be a sensible way to debug the failure.

On a standard environment one could go after /var/log/syslog or /var/log/cron.log, but here there's nothing if I log in to VM or even go after the main gaeapp container.

Any leads would be welcome!

Upvotes: 2

Views: 732

Answers (2)

Ain Tohvri
Ain Tohvri

Reputation: 3035

Cron log gets populated into the log of default service.

Instead of View link log of default service should be filtered for the Rake task route that the cron is calling.

Upvotes: 3

Alex
Alex

Reputation: 5276

I have a base http request handler that all the other request handlers inherit. I wrapped it up in a try-catch so that I can email myself the stack trace every time an exception occurs.

Here is how I did it in python/webapp2, I'm sure you could setup something similar in ruby. (alternatively you could use a product like https://rollbar.com/)

from google.appengine.api import mail, app_identity

def email_dev(subject, body):
    try:
        app_id = app_identity.get_application_id()
        mail.AdminEmailMessage(
            sender="%s <no-reply@%s.appspotmail.com>" % (app_id, app_id),
            subject=subject,
            body=body,
        ).send()
    except Exception as e:
        print("Error sending email: "+str(e))


class BaseHandler(webapp2.RequestHandler):

    def dispatch(self, *args, **kwargs):
        try:
            return super(BaseHandler, self).dispatch(*args, **kwargs)
        except Exception:
            email_dev(
                "Handler: "+self.__class__.__name__+" failed",
                traceback.format_exc())
            raise

Upvotes: -1

Related Questions