0
votes

I'm struggling to get a cron job working and get a 500 error.

My app.yaml file contains the following handler so it picks up the code

- url: /.*
  script: main.application

This is my cron.yaml

cron:
- description: my cron job
  url: /daily_batch
  schedule: every 10 minutes

main.py contains the following:

application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/daily_batch',DailyBatch),
], debug=True)

and this is how I code DailyBatch

class DailyBatch ():
    def get(self):
        myDefaults = DefaultData.query().fetch()
        for d in myDefaults:
            counter = 0

If I run this from a url it works fine but gives me a 500 error from cron. I'm being dumb. How?

Here's the error info I'm getting

ERROR    2015-12-28 10:57:20,056 webapp2.py:1552] this constructor takes no arguments

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__

    rv = self.handle_exception(request, response, e)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__

    rv = self.router.dispatch(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher

    return route.handler_adapter(request, response)

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1101, in __call__

    handler = self.handler(request, response)

TypeError: this constructor takes no arguments

INFO     2015-12-28 11:57:20,068 module.py:787] default: "GET /daily_batch HTTP/1.1" 500 1216
1
You need to provide the stack trace from the Error 500. - Tim Hoffman
You don't return anything from the get handler. Cron could be expecting valid response. - Tim Hoffman
got it. thanks. changed to class DailyBatch(webapp2.RequestHandler): - HenryM
right -- in webapp2, handlers (when routed to in the simplistic way) must subclass RequestHandler. So please post this as a self-answer and accept it, so the question will properly be seen as resolved. - Alex Martelli

1 Answers

0
votes

got it. thanks. changed to

class DailyBatch(webapp2.RequestHandler)