Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26642

How to solve my deadlineexceedederror for a GAE cron task?

I'm getting a deadlineexceedederror when trying to create a kml file by a cron that starts a task. The error message is

    2012-01-30 16:07:47.902 /createkml/ 500 5012ms 0kb AppEngine-Google; (+http://code.google.com/appengine)

    0.1.0.2 - - [30/Jan/2012:10:07:47 -0800] "POST /createkml/ HTTP/1.1" 500 0 "http://www.koolbusiness.com/createkmltask/" "AppEngine-Google; (+http://code.google.com/appengine)" "www.koolbusiness.com" ms=5013 cpu_ms=3305 api_cpu_ms=295 cpm_usd=0.091855 queue_name=default task_name=7177535986681131286 instance=00c61b117cf890b99ca52a6b9e7c5f048e72

    I 2012-01-30 16:07:42.959

    creating file

    E 2012-01-30 16:07:47.853

    ApplicationError: 5 
    Traceback (most recent call last):
      File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
        rv = self.handle_exception(request, response, e)
      File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
        rv = self.router.dispatch(request, response)
      File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
        return route.handler_adapter(request, response)
      File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
        return handler.dispatch()
      File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
        return self.handle_exception(e, self.app.debug)
      File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
        return method(*args, **kwargs)
      File "/base/data/home/apps/s~montaoproject/gralumo.356457066048686089/main.py", line 1575, in post
        result = urlfetch.fetch(url)
      File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 263, in fetch
        return rpc.get_result()
      File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 592, in get_result
        return self.__get_result_hook(self)
      File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 371, in _get_fetch_result
        raise DeadlineExceededError(str(err))

DeadlineExceededError: ApplicationError: 5 

My code is

class CreateKMLTask(webapp2.RequestHandler):

    def get(self):
        logging.info('creating KML task')
        taskqueue.add(url=r'/createkml/')
        self.redirect('/')

class CreateKMLHandler(webapp2.RequestHandler):

    def post(self):

        # Create the file
        logging.info('creating file')
        file_name = \
            files.blobstore.create(mime_type='application/octet-stream')

        url = 'http://montaoproject.appspot.com/list.kml'

        result = urlfetch.fetch(url)
        if not result.content:
            return

        # Open the file and write to it
        logging.info('opening file')

        with files.open(file_name, 'a') as f:
            f.write(result.content)

        # Finalize the file. Do this before attempting to read it.

        files.finalize(file_name)

        # Get the file's blob key
        logging.info('getting blob key of file')

        blob_key = files.blobstore.get_blob_key(file_name)
        logging.info('new blob key:'+str(blob_key))
        im = Image.get_by_id(4468185)
        im.primary_image = blob_key
        im.put()
        logging.info('new image key:'+str(im.primary_image))
        logging.info('finished KML handling and put image')


    webapp2.Route(r'/createkml/', handler=CreateKMLHandler,
                  name='createkml'),
    webapp2.Route(r'/createkmltask/', handler=CreateKMLTask,
                  name='createkmltask')

My cron.yaml:

cron:

 - description: daily mailout

   url: /report/daily

   schedule: every 24 hours

 - description: daily mailout

   url: /report/montaodaily

   schedule: every 24 hours

 - description: refresh kml

   url: /createkmltask/

   schedule: every 24 hours

What I'm trying to do is refresh to KML file to a new blob that has the same File ID as before so the call will be the same. What can I do to resolve my timeout problem? I think it should work.

Thanks

Upvotes: 1

Views: 830

Answers (1)

Jesse Rusak
Jesse Rusak

Reputation: 57188

This timeout is fetching the url; you can see this in the stack trace. The fetch function defaults to a 5-second timeout.

The URL Fetch docs say you can increase the timeout by passing deadline as an additional argument. For example, deadline=60 would give you a 60-second timeout.

So, try result = urlfetch.fetch(url, deadline=60)

Upvotes: 4

Related Questions