forked from CGM_Public/pretix_original
Refs #150 -- Trying to reduce latency
This commit is contained in:
@@ -39,43 +39,46 @@ class AsyncAction:
|
|||||||
return self.get_result(request)
|
return self.get_result(request)
|
||||||
return self.http_method_not_allowed(request)
|
return self.http_method_not_allowed(request)
|
||||||
|
|
||||||
|
def _return_celery_result(self, res, timeout=.5):
|
||||||
|
import celery.exceptions
|
||||||
|
|
||||||
|
if not res.ready():
|
||||||
|
try:
|
||||||
|
res.get(timeout=timeout)
|
||||||
|
except celery.exceptions.TimeoutError:
|
||||||
|
pass
|
||||||
|
ready = res.ready()
|
||||||
|
data = {
|
||||||
|
'async_id': res.id,
|
||||||
|
'ready': ready
|
||||||
|
}
|
||||||
|
if ready:
|
||||||
|
if res.successful() and not isinstance(res.info, Exception):
|
||||||
|
smes = self.get_success_message(res.info)
|
||||||
|
if smes:
|
||||||
|
messages.success(self.request, smes)
|
||||||
|
# TODO: Do not store message if the ajax client stats that it will not redirect
|
||||||
|
# but handle the mssage itself
|
||||||
|
data.update({
|
||||||
|
'redirect': self.get_success_url(res.info),
|
||||||
|
'message': str(self.get_success_message(res.info))
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
messages.error(self.request, self.get_error_message(res.info))
|
||||||
|
# TODO: Do not store message if the ajax client stats that it will not redirect
|
||||||
|
# but handle the mssage itself
|
||||||
|
data.update({
|
||||||
|
'redirect': self.get_error_url(),
|
||||||
|
'message': str(self.get_error_message(res.info))
|
||||||
|
})
|
||||||
|
return data
|
||||||
|
|
||||||
def get_result(self, request):
|
def get_result(self, request):
|
||||||
from celery.result import AsyncResult
|
from celery.result import AsyncResult
|
||||||
import celery.exceptions
|
|
||||||
|
|
||||||
res = AsyncResult(request.GET.get('async_id'))
|
res = AsyncResult(request.GET.get('async_id'))
|
||||||
if 'ajax' in self.request.GET:
|
if 'ajax' in self.request.GET:
|
||||||
if not res.ready():
|
return JsonResponse(self._return_celery_result(res, timeout=0.25))
|
||||||
try:
|
|
||||||
res.get(timeout=0.5)
|
|
||||||
except celery.exceptions.TimeoutError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
ready = res.ready()
|
|
||||||
data = {
|
|
||||||
'async_id': res.id,
|
|
||||||
'ready': ready
|
|
||||||
}
|
|
||||||
if ready:
|
|
||||||
if res.successful() and not isinstance(res.info, Exception):
|
|
||||||
smes = self.get_success_message(res.info)
|
|
||||||
if smes:
|
|
||||||
messages.success(self.request, smes)
|
|
||||||
# TODO: Do not store message if the ajax client stats that it will not redirect
|
|
||||||
# but handle the mssage itself
|
|
||||||
data.update({
|
|
||||||
'redirect': self.get_success_url(res.info),
|
|
||||||
'message': str(self.get_success_message(res.info))
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
messages.error(self.request, self.get_error_message(res.info))
|
|
||||||
# TODO: Do not store message if the ajax client stats that it will not redirect
|
|
||||||
# but handle the mssage itself
|
|
||||||
data.update({
|
|
||||||
'redirect': self.get_error_url(),
|
|
||||||
'message': str(self.get_error_message(res.info))
|
|
||||||
})
|
|
||||||
return JsonResponse(data)
|
|
||||||
else:
|
else:
|
||||||
if res.ready():
|
if res.ready():
|
||||||
if res.successful():
|
if res.successful():
|
||||||
@@ -85,14 +88,13 @@ class AsyncAction:
|
|||||||
return render(request, 'pretixpresale/waiting.html')
|
return render(request, 'pretixpresale/waiting.html')
|
||||||
|
|
||||||
def _do_celery(self, args):
|
def _do_celery(self, args):
|
||||||
rs = self.task.task.apply_async(args=args)
|
res = self.task.task.apply_async(args=args)
|
||||||
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
|
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
|
||||||
return JsonResponse({
|
data = self._return_celery_result(res)
|
||||||
'async_id': rs.id,
|
data['check_url'] = self.get_check_url(res.id, True)
|
||||||
'check_url': self.get_check_url(rs.id, True)
|
return JsonResponse(data)
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
return redirect(self.get_check_url(rs.id, False))
|
return redirect(self.get_check_url(res.id, False))
|
||||||
|
|
||||||
def _do_sync(self, args):
|
def _do_sync(self, args):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function async_task_callback(data, jqXHR, status) {
|
|||||||
}
|
}
|
||||||
async_task_id = data.async_id;
|
async_task_id = data.async_id;
|
||||||
async_task_check_url = data.check_url;
|
async_task_check_url = data.check_url;
|
||||||
async_task_timeout = window.setTimeout(async_task_check, 250);
|
async_task_timeout = window.setTimeout(async_task_check, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function async_task_error(jqXHR, textStatus, errorThrown) {
|
function async_task_error(jqXHR, textStatus, errorThrown) {
|
||||||
|
|||||||
Reference in New Issue
Block a user