Commit 32dfeb71 by Szeberényi Imre

Abortable task fix

parent 673168ca
......@@ -21,9 +21,11 @@
import logging
import uuid
import time
import re
from celery.contrib.abortable import AbortableAsyncResult
from celery.result import allow_join_result
from celery.exceptions import TimeoutError
from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse
......@@ -433,15 +435,15 @@ class Disk(TimeStampedModel):
@classmethod
def _run_abortable_task(cls, remote, task):
while True:
try:
result = remote.get(timeout=5)
break
except TimeoutError as e:
if task is not None and task.is_aborted():
AbortableAsyncResult(remote.id).abort()
raise humanize_exception(ugettext_noop(
"Operation aborted by user."), e)
while not remote.ready():
time.sleep(5)
logger.debug("Waiting for abortable task. Status: %s", AbortableAsyncResult(remote.id).status)
if task is not None and task.is_aborted():
AbortableAsyncResult(remote.id).abort()
raise humanize_exception(ugettext_noop("Operation aborted by user."), TimeoutError("Abort"))
with allow_join_result():
result = remote.get()
return result
@classmethod
......@@ -472,7 +474,7 @@ class Disk(TimeStampedModel):
result = cls._run_abortable_task(remote, task)
disk.size = result['size']
disk.type = result['type']
disk.checksum = result.get('checksum', None)
disk.checksum = result['checksum']
disk.is_ready = True
disk.save()
return disk
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment