aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/asynctask.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-01-04 17:41:18 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-01-10 10:03:24 +0000
commit63e75aad3b01de4fc20468d5dd9cdb9b15c5e11e (patch)
tree9f3600cb443029e0fbcec03c349d1b452dc2f938 /api/resources/asynctask.py
parent57011bd0769f54a98b90d489df0f38751ca76c0e (diff)
Add API to get the status of async task
JIRA: YARDSTICK-526 Currently there are many API run a task using sub thread. But we don't know the status of this task. So we need to offer a API to query the status of this task. Change-Id: I8d2cc558750bf9270aed4a7abb8bf35d17894d83 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources/asynctask.py')
-rw-r--r--api/resources/asynctask.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/api/resources/asynctask.py b/api/resources/asynctask.py
new file mode 100644
index 000000000..dd2a71003
--- /dev/null
+++ b/api/resources/asynctask.py
@@ -0,0 +1,35 @@
+# ############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+# ############################################################################
+import uuid
+
+from api.utils import common as common_utils
+from api.database.models import AsyncTasks
+
+
+def default(args):
+ return _get_status(args)
+
+
+def _get_status(args):
+ try:
+ task_id = args['task_id']
+ uuid.UUID(task_id)
+ except KeyError:
+ message = 'measurement and task_id must be provided'
+ return common_utils.error_handler(message)
+
+ asynctask = AsyncTasks.query.filter_by(task_id=task_id).first()
+
+ try:
+ status = asynctask.status
+ error = asynctask.error if asynctask.error else []
+
+ return common_utils.result_handler(status, error)
+ except AttributeError:
+ return common_utils.error_handler('no such task')