Files
controller-wisetopdataserver/python/biopro/project/task_manager.py
T

57 lines
1.6 KiB
Python
Raw Normal View History

2022-02-07 20:27:30 +08:00
from json import loads as json_parse, dumps as _json_stringify
from typing import Dict, Optional, Any
2022-02-10 00:49:49 +08:00
from xml.dom.expatbuilder import parseString
2022-02-07 20:27:30 +08:00
import paho.mqtt.client as mqtt
2022-03-07 16:57:32 +08:00
from biopro.text import *
2022-02-07 20:27:30 +08:00
from .task import Task
_RUNTIME_COMPILE = False
def json_stringify(o: Any) -> str:
return _json_stringify(o, separators=(',', ':'))
class TaskManager():
2022-02-10 00:49:49 +08:00
def __init__(self, task_list):
2022-02-17 20:35:36 +08:00
self._current_task = None
2022-02-12 00:21:27 +08:00
self._task_list = []
2022-02-17 20:35:36 +08:00
self._need_to_check_task_list = []
2022-02-12 00:21:27 +08:00
for task in task_list:
2022-02-25 20:54:58 +08:00
task = Task(task)
2022-02-17 20:35:36 +08:00
self._task_list.append(task)
self.set_current_task(self._task_list[0])
2022-02-14 19:19:54 +08:00
self._current_task.run()
2022-02-07 20:27:30 +08:00
def remove(self, index):
2022-02-08 20:12:44 +08:00
pass
2022-02-07 20:27:30 +08:00
2022-02-25 20:54:58 +08:00
def get_task(self, task_id):
return self._task_list[task_id]
2022-02-17 20:35:36 +08:00
def get_check_task_list(self):
return self._need_to_check_task_list
2022-02-07 20:27:30 +08:00
2022-03-02 18:13:02 +08:00
def get_current_task(self) -> Task:
2022-02-12 00:21:27 +08:00
return self._current_task
2022-02-17 20:35:36 +08:00
def get_next_task(self):
return self._current_task.next
def set_current_task(self, task):
2022-03-02 18:13:02 +08:00
try:
if self._current_task != None and self._current_task.id != task.id:
self._current_task.stop()
self._current_task = task
self._need_to_check_task_list = []
# append current task
self._need_to_check_task_list.append(self._current_task)
# append next task
for task_uuid in self._current_task.next:
task = next((task for task in self._task_list if task.uuid == task_uuid), None)
self._need_to_check_task_list.append(task)
except Exception as e:
print(e)