2012-02-29 70 views
0

我需要在有限的时间内获得将近100页,并将响应结果代码作为响应返回。 Google Apps一次限制10个异步请求。我在考虑排队,但他们在后台工作,也许收费应用程序可以帮助? 这里是我的代码,当有更多的则14页的URL []它失败:Google应用服务异步获取100次请求/秒

File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 371, in _get_fetch_result raise DeadlineExceededError(str(err)) DeadlineExceededError: ApplicationError: 5

class MainPage(webapp.RequestHandler): 
    results = [] 
    urls = [ "http://google.com/", 
      "http://yahoo.com", 
      "http://goo.gl", 
      "http://stackoverflow.com", 
      "http://windows.com", 
      "http://wikipedia.org" 
      ] 
    counter = len(urls) 

    def handle_result(self, rpc, rowIndex): 
     self.counter -= 1 
     result = rpc.get_result() 
     if result: 
     self.results.append(str(rowIndex)+": "+str(result.status_code)+"<br>") 
     if not self.counter: 
     self.response.out.write("".join(self.results)) 

    def create_callback(self, rpc, rowIndex): 
     return lambda: self.handle_result(rpc, rowIndex) 

    def get(self): 
     rpcs = [] 
     rowIndex = 0 
     for url in self.urls: 
     rpc = urlfetch.create_rpc(deadline = 10) 
     rpc.callback = self.create_callback(rpc, rowIndex) 
     urlfetch.make_fetch_call(rpc, url) 
     rpcs.append(rpc) 
     rowIndex += 1 
     # Finish all RPCs, and let callbacks process the results. 
     for rpc in rpcs: 
     rpc.wait() 

回答

0

您可以可排队的任务,然后使用channel API通知,将结果发送给用户。目前,频道只能使用Javascript客户端。谷歌计划实施其他语言的渠道客户,或者至少为希望编写其实施的人记录渠道客户。

+0

如果Channels与使用Google应用程序脚本向我的应用程序发出请求,那将会很不错。 – User 2012-03-01 09:31:46