aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/asynctask.py
blob: dd2a7100366a5046eac4deb91b5b894551bddb03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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')