X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=api%2Futils%2Fdaemonthread.py;h=0049834eba889b0ce7780f17741b7d448a44ffd9;hb=13d09b66c8e2dba58056513093e71b77f255cc97;hp=77a0f6ab7ec931d773d7b21050b8a63305fa02d3;hpb=eec370bc52caee7fe1633ae9f3ec8ac85ac50119;p=yardstick.git diff --git a/api/utils/daemonthread.py b/api/utils/daemonthread.py index 77a0f6ab7..0049834eb 100644 --- a/api/utils/daemonthread.py +++ b/api/utils/daemonthread.py @@ -1,10 +1,18 @@ +############################################################################## +# Copyright (c) 2016 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 +############################################################################## +from __future__ import absolute_import import threading import os -import datetime import errno from api import conf -from api.utils.influx import write_data_tasklist +from api.database.handlers import TasksHandler class DaemonThread(threading.Thread): @@ -13,19 +21,24 @@ class DaemonThread(threading.Thread): super(DaemonThread, self).__init__(target=method, args=args) self.method = method self.command_list = args[0] - self.task_id = args[1] + self.task_dict = args[1] def run(self): - timestamp = datetime.datetime.now() + self.task_dict['status'] = 0 + task_id = self.task_dict['task_id'] try: - write_data_tasklist(self.task_id, timestamp, 0) - self.method(self.command_list, self.task_id) - write_data_tasklist(self.task_id, timestamp, 1) + task_handler = TasksHandler() + task = task_handler.insert(self.task_dict) + + self.method(self.command_list, task_id) + + task_handler.update_status(task, 1) except Exception as e: - write_data_tasklist(self.task_id, timestamp, 2, error=str(e)) + task_handler.update_status(task, 2) + task_handler.update_error(task, str(e)) finally: - _handle_testsuite_file(self.task_id) + _handle_testsuite_file(task_id) def _handle_testsuite_file(task_id):