1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from lcm.workflows.graphflow import STARTED, PROCESSING, FINISHED, ERROR, TIMEOUT_DEFAULT
19 logger = logging.getLogger(__name__)
23 TASK_STATUS = (STARTED, PROCESSING, FINISHED, ERROR) = (STARTED, PROCESSING, FINISHED, ERROR)
24 TASK_ATTRIBUTES = (KEY, MANAGER, INPUT, TIMEOUT, ENDTIME, OUTPUT, STATUS) = ("key", "manager", "input", "timeout", "endtime", "output", "status")
25 INPUT_REST = (URL, METHOD, CONTENT) = ("url", "method", "content")
26 TIMEOUT_DEFAULT = TIMEOUT_DEFAULT
27 TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
29 def __init__(self, *args):
31 self.key = task[self.KEY]
32 self.taskManager = task[self.MANAGER]
33 self.input = task[self.INPUT]
34 self.timeout = task[self.TIMEOUT] if self.TIMEOUT in task else self.TIMEOUT_DEFAULT
35 self.endtime = (datetime.datetime.now() + datetime.timedelta(seconds=self.timeout)).strftime(self.TIME_FORMAT)
42 def update_task(self, status, output=None):
43 task = self.taskManager.get_task(self.key)
47 logger.debug("Update task %s status %s" % (task.key, task.status))
48 self.taskManager.update_task(self.key, task)