ジョブのステータスを取得する必要があり、ジョブの計算を処理する新しいスレッドを生成するとします。
def post_view(request):
g = Greenlet.spawn(heavy_job, arg1, arg2)
return json.dumps(default_response)
そして、heavy_job で
def heavy_job(...):
# call a 3rd party service to start doing its job
job_id = (....)
request.session['heavy_job_status'] = 'Running'
status = 'Running'
while status == 'Running':
# ask the 3rd party guy "are you still running"
resp = 3rdparty-service.query(job_id, ....)
if resp != 'Running':
return resp
time.sleep(5) # we will monkey patch the time with gevent's timer so no locking
この while ループ アプローチはスケーリングにとって本当に悪いのでしょうか? それとも、各 ajax リクエストが着信するたびにサードパーティ サービスにクエリを実行しますか?