refactor(dag): Audit and cleanup dag_engine.py
This commit is contained in:
+12
-20
@@ -61,6 +61,14 @@ class TrackDAG:
|
|||||||
changed = True
|
changed = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def is_ticket_ready(self, ticket: Ticket) -> bool:
|
||||||
|
"""Returns True if all dependencies of the ticket are completed."""
|
||||||
|
for dep_id in ticket.depends_on:
|
||||||
|
dep = self.ticket_map.get(dep_id)
|
||||||
|
if not dep or dep.status != 'completed':
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def get_ready_tasks(self) -> List[Ticket]:
|
def get_ready_tasks(self) -> List[Ticket]:
|
||||||
"""
|
"""
|
||||||
Returns a list of tickets that are in 'todo' status and whose dependencies are all 'completed'.
|
Returns a list of tickets that are in 'todo' status and whose dependencies are all 'completed'.
|
||||||
@@ -69,16 +77,8 @@ class TrackDAG:
|
|||||||
"""
|
"""
|
||||||
ready = []
|
ready = []
|
||||||
for ticket in self.tickets:
|
for ticket in self.tickets:
|
||||||
if ticket.status == 'todo':
|
if ticket.status == 'todo' and self.is_ticket_ready(ticket):
|
||||||
# Check if all dependencies exist and are completed
|
ready.append(ticket)
|
||||||
all_done = True
|
|
||||||
for dep_id in ticket.depends_on:
|
|
||||||
dep = self.ticket_map.get(dep_id)
|
|
||||||
if not dep or dep.status != 'completed':
|
|
||||||
all_done = False
|
|
||||||
break
|
|
||||||
if all_done:
|
|
||||||
ready.append(ticket)
|
|
||||||
return ready
|
return ready
|
||||||
|
|
||||||
def has_cycle(self) -> bool:
|
def has_cycle(self) -> bool:
|
||||||
@@ -172,16 +172,8 @@ class ExecutionEngine:
|
|||||||
task_id: The ID of the task to approve.
|
task_id: The ID of the task to approve.
|
||||||
"""
|
"""
|
||||||
ticket = self.dag.ticket_map.get(task_id)
|
ticket = self.dag.ticket_map.get(task_id)
|
||||||
if ticket and ticket.status == "todo":
|
if ticket and ticket.status == "todo" and self.dag.is_ticket_ready(ticket):
|
||||||
# Check if dependencies are met first
|
ticket.status = "in_progress"
|
||||||
all_done = True
|
|
||||||
for dep_id in ticket.depends_on:
|
|
||||||
dep = self.dag.ticket_map.get(dep_id)
|
|
||||||
if not dep or dep.status != "completed":
|
|
||||||
all_done = False
|
|
||||||
break
|
|
||||||
if all_done:
|
|
||||||
ticket.status = "in_progress"
|
|
||||||
|
|
||||||
def update_task_status(self, task_id: str, status: str) -> None:
|
def update_task_status(self, task_id: str, status: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user