Как решить мой дедлайн exceedederror для задачи cron GAE? - PullRequest
1 голос
/ 30 января 2012

Я получаю deadlineexceedederror при попытке создать файл kml cron, который запускает задачу.Сообщение об ошибке:

    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 

Мой код:

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')

Мой 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

Я пытаюсь выполнить обновление до KMLфайл в новый BLOB-объект, имеющий тот же идентификатор файла, что и раньше, поэтому вызов будет таким же.Что я могу сделать, чтобы решить мою проблему тайм-аута?Я думаю, что это должно работать.

Спасибо

1 Ответ

4 голосов
/ 31 января 2012

Это время ожидания получения URL;Вы можете увидеть это в трассировке стека.По умолчанию функция выборки имеет 5-секундный тайм-аут.

URL Fetch docs говорит, что вы можете увеличить время ожидания, передав крайний срок в качестве дополнительного аргумента.Например, крайний срок = 60 даст вам 60-секундный тайм-аут.

Итак, попробуйте result = urlfetch.fetch(url, deadline=60)

...