57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
from json import loads as json_parse, dumps as _json_stringify
|
|
from typing import Dict, Optional, Any
|
|
from xml.dom.expatbuilder import parseString
|
|
import paho.mqtt.client as mqtt
|
|
from biopro.text import *
|
|
from .task import Task
|
|
|
|
_RUNTIME_COMPILE = False
|
|
|
|
def json_stringify(o: Any) -> str:
|
|
return _json_stringify(o, separators=(',', ':'))
|
|
|
|
class TaskManager():
|
|
def __init__(self, task_list):
|
|
self._current_task = None
|
|
self._task_list = []
|
|
self._need_to_check_task_list = []
|
|
|
|
for task in task_list:
|
|
task = Task(task)
|
|
self._task_list.append(task)
|
|
|
|
self.set_current_task(self._task_list[0])
|
|
self._current_task.run()
|
|
|
|
def remove(self, index):
|
|
pass
|
|
|
|
def get_task(self, task_id):
|
|
return self._task_list[task_id]
|
|
|
|
def get_check_task_list(self):
|
|
return self._need_to_check_task_list
|
|
|
|
def get_current_task(self) -> Task:
|
|
return self._current_task
|
|
|
|
def get_next_task(self):
|
|
return self._current_task.next
|
|
|
|
def set_current_task(self, task):
|
|
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)
|