MCPcopy Create free account
hub / github.com/OpenBMB/RepoAgent / TaskManager

Class TaskManager

repo_agent/multi_task_dispatch.py:19–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19class TaskManager:
20 def __init__(self):
21 """
22 Initialize a MultiTaskDispatch object.
23
24 This method initializes the MultiTaskDispatch object by setting up the necessary attributes.
25
26 Attributes:
27 - task_dict (Dict[int, Task]): A dictionary that maps task IDs to Task objects.
28 - task_lock (threading.Lock): A lock used for thread synchronization when accessing the task_dict.
29 - now_id (int): The current task ID.
30 - query_id (int): The current query ID.
31 - sync_func (None): A placeholder for a synchronization function.
32
33 """
34 self.task_dict: Dict[int, Task] = {}
35 self.task_lock = threading.Lock()
36 self.now_id = 0
37 self.query_id = 0
38
39 @property
40 def all_success(self) -> bool:
41 return len(self.task_dict) == 0
42
43 def add_task(self, dependency_task_id: List[int], extra=None) -> int:
44 """
45 Adds a new task to the task dictionary.
46
47 Args:
48 dependency_task_id (List[int]): List of task IDs that the new task depends on.
49 extra (Any, optional): Extra information associated with the task. Defaults to None.
50
51 Returns:
52 int: The ID of the newly added task.
53 """
54 with self.task_lock:
55 depend_tasks = [self.task_dict[task_id] for task_id in dependency_task_id]
56 self.task_dict[self.now_id] = Task(
57 task_id=self.now_id, dependencies=depend_tasks, extra_info=extra
58 )
59 self.now_id += 1
60 return self.now_id - 1
61
62 def get_next_task(self, process_id: int):
63 """
64 Get the next task for a given process ID.
65
66 Args:
67 process_id (int): The ID of the process.
68
69 Returns:
70 tuple: A tuple containing the next task object and its ID.
71 If there are no available tasks, returns (None, -1).
72 """
73 with self.task_lock:
74 self.query_id += 1
75 for task_id in self.task_dict.keys():
76 ready = (

Callers 2

get_task_managerMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected