MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / BackgroundTaskManager

Class BackgroundTaskManager

core/background.py:61–241  ·  view source on GitHub ↗

Manages background tasks for Codey-v2. Features: - Start/stop tasks - Timeout enforcement - Resource tracking - File watch integration

Source from the content-addressed store, hash-verified

59
60
61class BackgroundTaskManager:
62 """
63 Manages background tasks for Codey-v2.
64
65 Features:
66 - Start/stop tasks
67 - Timeout enforcement
68 - Resource tracking
69 - File watch integration
70 """
71
72 def __init__(self):
73 self._tasks: Dict[str, BackgroundTask] = {}
74 self._running: bool = False
75 self._task_counter: int = 0
76
77 def _generate_id(self) -> str:
78 """Generate unique task ID."""
79 self._task_counter += 1
80 return f"bg_{self._task_counter}_{int(time.time())}"
81
82 def add_task(self, name: str, func: Callable,
83 timeout: float = 1800, **metadata) -> str:
84 """
85 Add a background task.
86
87 Args:
88 name: Task name
89 func: Async function to run
90 timeout: Maximum runtime in seconds
91 **metadata: Additional task metadata
92
93 Returns:
94 Task ID
95 """
96 task_id = self._generate_id()
97 task = BackgroundTask(
98 id=task_id,
99 name=name,
100 func=func,
101 timeout=timeout,
102 metadata=metadata,
103 )
104 self._tasks[task_id] = task
105 info(f"Background: added task '{name}' (ID: {task_id})")
106 return task_id
107
108 async def start_task(self, task_id: str) -> bool:
109 """
110 Start a background task.
111
112 Args:
113 task_id: Task ID to start
114
115 Returns:
116 True if started successfully
117 """
118 task = self._tasks.get(task_id)

Callers 1

get_background_managerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected