-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskManager.py
48 lines (38 loc) · 1.21 KB
/
TaskManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from asyncio import sleep
from formsParser import AsyncDataSender
class Task:
def __init__(self, sender: AsyncDataSender):
self.sender = sender
self.name = sender.parser.title
def check_alive(self):
return self.sender.check_alive()
def start(self):
self.sender.get_probs_of_answers()
self.sender.get_naked_options()
self.sender.work()
class TaskManager:
def __init__(self):
self.all_tasks = []
self.task_indexer = {}
def put(self, _id, task: Task):
self.all_tasks.append(task)
self.task_indexer[_id] = self.all_tasks.index(task)
def get(self, _id):
_ind = self.task_indexer.get(_id, -1)
# print('###')
# print(_id)
# print(self.task_indexer)
# print(self.all_tasks)
# print('###')
if _ind == -1:
raise ValueError("TASK NOT FOUND")
else:
return self.all_tasks[_ind]
def remove(self, _id):
_ind = self.task_indexer.get(_id, 0)
if not _ind:
print(self.task_indexer)
raise ValueError("TASK NOT FOUND")
else:
self.task_indexer[_id] = None
self.all_tasks[_ind] = None