From 50c045e91636d2c262c98e88f9e8f298334081c1 Mon Sep 17 00:00:00 2001 From: Guba Sándor Date: Fri, 6 Jun 2014 13:46:28 +0200 Subject: [PATCH] vm: added has_ercentage and get_percentage to activities --- circle/vm/models/activity.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/circle/vm/models/activity.py b/circle/vm/models/activity.py index 90b6c22..b0cd1ac 100644 --- a/circle/vm/models/activity.py +++ b/circle/vm/models/activity.py @@ -116,6 +116,17 @@ class InstanceActivity(ActivityModel): else: return 'failed' + def has_percentage(self): + op = self.instance.get_operation_from_activity_code(self.activity_code) + return (self.task_uuid and op and op.has_percentage + and not self.finished) + + def get_percentage(self): + """Returns the percentage of the running operation if available. + """ + if self.has_percentage(): + celery.AsyncResult(id=self.task_uuid).info.get("percent") + @property def is_abortable(self): """Can the activity be aborted? -- libgit2 0.26.0