Commit 32dfeb71 by Szeberényi Imre

Abortable task fix

parent 673168ca
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
import logging import logging
import uuid import uuid
import time
import re import re
from celery.contrib.abortable import AbortableAsyncResult from celery.contrib.abortable import AbortableAsyncResult
from celery.result import allow_join_result
from celery.exceptions import TimeoutError from celery.exceptions import TimeoutError
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse from django.urls import reverse
...@@ -433,15 +435,15 @@ class Disk(TimeStampedModel): ...@@ -433,15 +435,15 @@ class Disk(TimeStampedModel):
@classmethod @classmethod
def _run_abortable_task(cls, remote, task): def _run_abortable_task(cls, remote, task):
while True: while not remote.ready():
try: time.sleep(5)
result = remote.get(timeout=5) logger.debug("Waiting for abortable task. Status: %s", AbortableAsyncResult(remote.id).status)
break if task is not None and task.is_aborted():
except TimeoutError as e: AbortableAsyncResult(remote.id).abort()
if task is not None and task.is_aborted(): raise humanize_exception(ugettext_noop("Operation aborted by user."), TimeoutError("Abort"))
AbortableAsyncResult(remote.id).abort()
raise humanize_exception(ugettext_noop( with allow_join_result():
"Operation aborted by user."), e) result = remote.get()
return result return result
@classmethod @classmethod
...@@ -472,7 +474,7 @@ class Disk(TimeStampedModel): ...@@ -472,7 +474,7 @@ class Disk(TimeStampedModel):
result = cls._run_abortable_task(remote, task) result = cls._run_abortable_task(remote, task)
disk.size = result['size'] disk.size = result['size']
disk.type = result['type'] disk.type = result['type']
disk.checksum = result.get('checksum', None) disk.checksum = result['checksum']
disk.is_ready = True disk.is_ready = True
disk.save() disk.save()
return disk 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