2012-02-29 3 views
0

限られた時間でほぼ100ページを取得し、結果コードを返信する必要があります。 Google Appsには、一度に10個の非同期要求があるという制限があります。私はキューを考えていますが、バックグラウンドで作業しています。Google Apps async-fetch for 100 req/sec

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を使用して、タスクをキューに入れることができます。ここでは はもっとして14件のURL []それはで失敗があったときに、私のコードです。現在、チャンネルはJavascriptクライアントでのみ動作します。 Googleはチャネルクライアントを他の言語で実装したり、少なくともそれらの実装を書こうとする人のためにチャネルクライアントを文書化する予定です。

+0

私のアプリにリクエストを送るGoogle App Scriptでチャンネルが機能することは素晴らしいことでしょう。 – User

関連する問題