Merge "Bugfix: Could not load EntryPoint.parse when using 'openstack -h'"
[yardstick.git] / api / database / handler.py
1 # ############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 # ############################################################################
9 from api.database import db_session
10 from api.database.models import AsyncTasks
11
12
13 class AsyncTaskHandler(object):
14     def insert(self, kwargs):
15         task = AsyncTasks(**kwargs)
16         db_session.add(task)
17         db_session.commit()
18         return task
19
20     def update_status(self, task, status):
21         task.status = status
22         db_session.commit()
23
24     def update_error(self, task, error):
25         task.error = error
26         db_session.commit()
27
28     def get_task_by_taskid(self, task_id):
29         task = AsyncTasks.query.filter_by(task_id=task_id).first()
30         return task