MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / TaskChannel

Class TaskChannel

camel/societies/workforce/task_channel.py:78–182  ·  view source on GitHub ↗

r"""An internal class used by Workforce to manage tasks.

Source from the content-addressed store, hash-verified

76
77
78class TaskChannel:
79 r"""An internal class used by Workforce to manage tasks."""
80
81 def __init__(self) -> None:
82 self._task_id_list: List[str] = []
83 self._condition = asyncio.Condition()
84 self._task_dict: Dict[str, Packet] = {}
85
86 async def get_returned_task_by_publisher(self, publisher_id: str) -> Task:
87 r"""Get a task from the channel that has been returned by the
88 publisher.
89 """
90 async with self._condition:
91 while True:
92 for task_id in self._task_id_list:
93 packet = self._task_dict[task_id]
94 if packet.publisher_id != publisher_id:
95 continue
96 if packet.status != PacketStatus.RETURNED:
97 continue
98 return packet.task
99 await self._condition.wait()
100
101 async def get_assigned_task_by_assignee(self, assignee_id: str) -> Task:
102 r"""Get a task from the channel that has been assigned to the
103 assignee.
104 """
105 async with self._condition:
106 while True:
107 for task_id in self._task_id_list:
108 packet = self._task_dict[task_id]
109 if (
110 packet.status == PacketStatus.SENT
111 and packet.assignee_id == assignee_id
112 ):
113 return packet.task
114 await self._condition.wait()
115
116 async def post_task(
117 self, task: Task, publisher_id: str, assignee_id: str
118 ) -> None:
119 r"""Send a task to the channel with specified publisher and assignee,
120 along with the dependency of the task."""
121 async with self._condition:
122 self._task_id_list.append(task.id)
123 packet = Packet(task, publisher_id, assignee_id)
124 self._task_dict[packet.task.id] = packet
125 self._condition.notify_all()
126
127 async def post_dependency(
128 self, dependency: Task, publisher_id: str
129 ) -> None:
130 r"""Post a dependency to the channel. A dependency is a task that is
131 archived, and will be referenced by other tasks."""
132 async with self._condition:
133 self._task_id_list.append(dependency.id)
134 packet = Packet(
135 dependency, publisher_id, status=PacketStatus.ARCHIVED

Callers 3

__init__Method · 0.90
resetMethod · 0.90
process_taskMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected