これはおそらく基本的な質問ですが、私は答えを見つけることができませんでした。
数分ごとにデータを生成する長時間実行プロセスがあり、準備ができたらすぐにクライアントに受信してもらいたいと考えています。現在、タスクキューに長時間実行されているプロセスがあり、forループ内から別のタスクキューにチャネルメッセージを追加します。クライアントはチャネルメッセージを正常に受信し、getリクエストを使用してデータをダウンロードします。ただし、メッセージは、メッセージがタスクキューに追加されたときではなく、長時間実行されたプロセスが終了した後(約10分後)にタスクキューから送信されます。
タスクキュー内のメッセージをすぐに送信するにはどうすればよいですか?forループをいくつかのタスクに分割する必要がありますか?forループは、タスクからデータを返す簡単な方法がない限り、データストアに投稿してから、次の反復のために取得する必要があると思う辞書をいくつか作成します(理想的な解決策とは思えません)。
メッセージをタスクキューに追加せず、メッセージをforループで直接送信しない場合、サーバーはクライアントのデータの取得要求に応答していないようです(おそらく、長時間実行されているプロセスのブロックのforループが原因です)応答?)
これが私のサーバーコードの簡略版です:
from google.appengine.ext import db
from google.appengine.api import channel
from google.appengine.api import taskqueue
from google.appengine.api import rdbms
class MainPage(webapp2.RequestHandler):
def get(self):
## This opens the GWT app
class Service_handler(webapp2.RequestHandler):
def get(self, parameters):
## This is called by the GWT app and generates the data to be
## sent to the client.
#This adds the long-process to a task queue
taskqueue.Task(url='/longprocess/', params = {'json_request': json_request}).add(queue_name='longprocess-queue')
class longprocess_handler(webapp2.RequestHandler):
def post(self):
#This has a for loop that recursively uses data in dictionaries to
#produce kml files every few minutes
for j in range(0, Time):
# Process data
# Send message to client using a task queue to send the message.
taskqueue.Task(url='/send/', params).add(queue_name=send_queue_name)
class send_handler(webapp2.RequestHandler):
def post(self):
# This sends the message to the client
# This is currently not happening until the long-process finishes,
# but I would like it to occur immediately.
class kml_handler(webapp2.RequestHandler):
def get(self, client_id):
## When the client receives the message, it picks up the data here.
app = webapp2.WSGIApplication([
webapp2.Route(r'/', handler=MainPage),
webapp2.Route(r'/Service/', handler=Service_handler),
webapp2.Route(r'/_ah/channel/<connected>/', handler = connection_handler),
webapp2.Route(r'/longprocess/', handler = longprocess_handler),
webapp2.Route(r'/kml/<client_id>', handler = kml_handler),
webapp2.Route(r'/send/', handler = send_handler)
],
debug=True)
send_handlerをすぐに実行するために、長いプロセスをデータストアから結果を送信および取得するタスクに分割する必要がありますか、それとも何かが足りませんか?ありがとう