S SmartDocs
Series: Humanoid python 94 lines · Updated 2026-05-12

__init__.py

Humanoid/May_12/RoboOS/master/task_manager/__init__.py

# -*- coding: utf-8 -*-
"""Task Manager 套件入口。

依照架構教學文件 §8 推薦的目錄結構:

    task_manager/
        __init__.py
        events.py         - 事件 dataclass
        context.py        - TaskContext + Redis 持久化
        queue.py          - TaskQueueManager (max=3 滑窗)
        runtime.py        - 單一任務 FSM
        diagnostics.py    - 故障識別 / 分類
        monitor.py        - 視覺 / 技能事件 listener
        scheduler.py      - 任務狀態機 + 派發
        hmi.py            - Flask blueprint + WebSocket bridge
        interfaces.md     - 對外合約

主要對外類別:
    TaskScheduler         - 任務調度狀態機
    TaskMonitor           - 事件監控
    TaskDiagnostics       - 故障診斷
    TaskQueueManager      - 任務隊列
    ContextStore          - 任務上下文存儲
    TaskRuntime           - 單一任務 FSM
"""
from .context import ContextStore, TaskContext, new_task_id
from .diagnostics import FAULT_TABLE, DiagnoseDecision, TaskDiagnostics
from .events import (
    BARCODE_FACE_VALUES,
    FaultRecord,
    ProgressEvent,
    SkillEvent,
    VisionFrame,
    VisionObservation,
    ZONE_VALUES,
)
from .monitor import TaskMonitor
from .queue import TaskQueueManager
from .runtime import PROGRESS_MAP, TaskRuntime, TaskState, Transition
from .scheduler import SchedMode, SchedState, TaskScheduler, extract_package_id

# HMI 依賴 flask;若未安裝則跳過(不阻擋核心模塊使用)
try:
    from .hmi import WSBridge, make_blueprint, register
except ImportError as _hmi_err:  # pragma: no cover
    import logging as _logging

    _logging.getLogger(__name__).warning(
        "[task_manager] HMI module disabled: %s "
        "(install 'flask' + 'flask-socketio' to enable HTTP/WS endpoints)",
        _hmi_err,
    )
    WSBridge = None  # type: ignore[assignment]
    make_blueprint = None  # type: ignore[assignment]
    register = None  # type: ignore[assignment]

__version__ = "0.1.0"

__all__ = [
    # context
    "ContextStore",
    "TaskContext",
    "new_task_id",
    # events
    "VisionObservation",
    "VisionFrame",
    "SkillEvent",
    "FaultRecord",
    "ProgressEvent",
    "BARCODE_FACE_VALUES",
    "ZONE_VALUES",
    # queue
    "TaskQueueManager",
    # runtime
    "TaskRuntime",
    "TaskState",
    "Transition",
    "PROGRESS_MAP",
    # diagnostics
    "TaskDiagnostics",
    "DiagnoseDecision",
    "FAULT_TABLE",
    # monitor
    "TaskMonitor",
    # scheduler
    "TaskScheduler",
    "SchedState",
    "SchedMode",
    "extract_package_id",
    # hmi
    "register",
    "make_blueprint",
    "WSBridge",
]

Related articles