Commit f931d0f6 by Guba Sándor

storage: changed is_downloading and get_download_precentage

parent 1135d99d
...@@ -17,7 +17,8 @@ from acl.models import AclBase ...@@ -17,7 +17,8 @@ from acl.models import AclBase
from .tasks import local_tasks, remote_tasks from .tasks import local_tasks, remote_tasks
from celery.exceptions import TimeoutError from celery.exceptions import TimeoutError
from manager.mancelery import celery from manager.mancelery import celery
from common.models import ActivityModel, activitycontextimpl, WorkerNotFound from common.models import (ActivityModel, activitycontextimpl,
WorkerNotFound, method_cache)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -111,6 +112,7 @@ class Disk(AclBase, TimeStampedModel): ...@@ -111,6 +112,7 @@ class Disk(AclBase, TimeStampedModel):
return self.activity_log.filter(activity_code__endswith="deploy", return self.activity_log.filter(activity_code__endswith="deploy",
succeeded__isnull=False) succeeded__isnull=False)
@property
def path(self): def path(self):
"""The path where the files are stored. """The path where the files are stored.
""" """
...@@ -153,15 +155,16 @@ class Disk(AclBase, TimeStampedModel): ...@@ -153,15 +155,16 @@ class Disk(AclBase, TimeStampedModel):
}[self.type] }[self.type]
def is_downloading(self): def is_downloading(self):
da = DiskActivity.objects.filter(disk=self).latest("created") return self.activity_log.filter(
return (da.activity_code == "storage.Disk.download" activity_code__endswith="downloading_disk",
and da.succeeded is None) succeeded__isnull=True)
def get_download_percentage(self): def get_download_percentage(self):
if not self.is_downloading(): if not self.is_downloading():
return None return None
task = self.activity_log.filter(
task = DiskActivity.objects.latest("created").task_uuid activity_code__endswith="deploy",
succeeded__isnull=True)[0].task_uuid
result = celery.AsyncResult(id=task) result = celery.AsyncResult(id=task)
return result.info.get("percent") return result.info.get("percent")
...@@ -270,8 +273,7 @@ class Disk(AclBase, TimeStampedModel): ...@@ -270,8 +273,7 @@ class Disk(AclBase, TimeStampedModel):
self.save() self.save()
if self.ready: if self.ready:
return False return True
with disk_activity(code_suffix='deploy', disk=self, with disk_activity(code_suffix='deploy', disk=self,
task_uuid=task_uuid, user=user) as act: task_uuid=task_uuid, user=user) as act:
...@@ -289,9 +291,6 @@ class Disk(AclBase, TimeStampedModel): ...@@ -289,9 +291,6 @@ class Disk(AclBase, TimeStampedModel):
queue=queue_name queue=queue_name
).get(timeout=timeout) ).get(timeout=timeout)
self.ready = True
self.save()
return True return True
def deploy_async(self, user=None): def deploy_async(self, user=None):
......
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