Task Manager
- class bedrock_server_manager.web.tasks.TaskManager(app_context: AppContext, max_workers: int | None = None)
Bases:
objectManages background tasks using a thread pool.
- __init__(app_context: AppContext, max_workers: int | None = None)
Initializes the TaskManager and the thread pool executor.
- run_task(target_function: Callable, username: str | None = None, *args: Any, **kwargs: Any) str
Submits a function to be run in the background.
- Parameters:
target_function – The function to execute.
username – The user associated with the task for WebSocket notifications.
*args – Positional arguments for the target function.
**kwargs – Keyword arguments for the target function.
- Returns:
The ID of the created task.
- get_task(task_id: str) Dict[str, Any] | None
Retrieves the status of a task.
- get_all_tasks() Dict[str, Dict[str, Any]]
Retrieves all tasks.
- shutdown()
Shuts down the thread pool and waits for all tasks to complete.