Skip to content

Commit

Permalink
fix task starting issue in dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
dewmal committed Sep 2, 2024
1 parent d8095e3 commit 92c64a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bindings/ceylon/ceylon/task/task_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async def run_tasks(self):
self.results[task.id] = []
sub_tasks = task.get_next_subtasks()
if len(sub_tasks) == 0:
logger.info(f"Task {task.name} has no subtasks")
continue
for sub_task in sub_tasks:
if sub_task is None:
Expand Down Expand Up @@ -119,9 +120,9 @@ async def on_agent_connected(self, topic: "str", agent: AgentDetail):
await super().on_agent_connected(topic, agent)
await self.run_tasks()

def add_tasks(self, tasks: List[Task]):
async def add_tasks(self, tasks: List[Task]):
self.tasks.extend(tasks)
self.on_init()
await self.run_tasks()

async def add_task(self, task: Task):
self.tasks.extend([task])
Expand All @@ -133,4 +134,6 @@ def add_agents(self, agents: List[TaskOperator]):

@on_message(type=Task)
async def on_add_task(self, task: Task):
self.add_tasks([task])
logger.info(f"Adding task {task} to coordinator")
task.reinitialize()
await self.add_tasks([task])
12 changes: 12 additions & 0 deletions bindings/ceylon/ceylon/task/task_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def __str__(self):
status = "Completed" if self.completed else "Pending"
return f"SubTask: {self.name} (ID: {self.id}) - {status} - Dependencies: {self.depends_on}"

def reset(self):
self.result = None
self.completed_at = None
self.completed = False


class TaskDeliverable(BaseModel):
objective: str = Field(
Expand Down Expand Up @@ -76,6 +81,13 @@ class Task(BaseModel):

max_subtasks: int = Field(default=5, description="max number of subtasks")

def reinitialize(self):
for subtask in self.subtasks.values():
subtask.parent_task_id = self.id
subtask.reset()
self._validate_dependencies()
self.execution_order = self.get_execution_order()

def add_subtask(self, subtask: SubTask):
subtask.parent_task_id = self.id
self.subtasks[subtask.name] = subtask
Expand Down

0 comments on commit 92c64a3

Please sign in to comment.