2012-01-30 85 views
1

尝试通过启动任务的cron创建kml文件时,我收到了deadlineexceedederror。该错误消息是如何解决我的GAE cron任务的deadlineexceedederror?

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文件到一个新斑块是具有与以前相同的文件ID,因此呼叫将相同。我能做些什么来解决我的超时问题?我认为它应该工作。

谢谢

+1

是 'http://montaoproject.appspot.com/list.kml' 由CreateKMLHandler处理器的同一个应用程序提供服务?为什么使用urlfetch访问它? – systempuntoout 2012-01-30 20:12:12

+0

@systempuntoout我第一次尝试使它像一个正常生成KML的常规处理程序。这反过来给了我超时的问题,我把它放在一个任务中,并通过cron更新它可以解决超时问题。当它工作时,它工作得很好,但它需要5秒加载。如果仍然失败,我可能会将此用例完全更改为Google地图以外的其他内容,并创建自己的地图。 – 2012-01-30 20:38:26

回答

4

这个超时是获取url;你可以在堆栈跟踪中看到它。提取功能默认为5秒超时。

URL Fetch docs表示您可以通过将截止日期作为附加参数来增加超时。例如,截止日期= 60会给你60秒的超时时间。

所以,尽量result = urlfetch.fetch(url, deadline=60)

+0

非常感谢。我现在正在尝试这个设置,因为它是一个很好的答案,所以不需要我重新编码整个事物:-)会奖励你一个赏金 – 2012-01-30 21:05:24