Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions inorbit_connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import threading
import traceback
from abc import ABC, abstractmethod
from typing import Coroutine
from typing import Any, Callable, Coroutine

# Python 3.12+ compatibility for override decorator
try:
Expand Down Expand Up @@ -61,6 +61,12 @@
RobotConfig,
)

# Zero-arg callable returning a fresh coroutine: what ``_create_supervised_task`` runs.
CoroutineFactory = Callable[[], Coroutine[Any, Any, None]]
# Scheduler signature of ``_create_supervised_task``; pollers that accept an injected
# scheduler (so they can be tested standalone) should type the parameter with this.
SupervisedTaskFactory = Callable[[str, CoroutineFactory], asyncio.Task]


class FleetConnector(ABC):
"""Generic InOrbit fleet connector.
Expand Down Expand Up @@ -654,7 +660,7 @@ def _is_session_connected(self, robot_id: str) -> bool:
return False

def _create_supervised_task(
self, name: str, coro_factory, restart_delay: float = 5.0
self, name: str, coro_factory: CoroutineFactory, restart_delay: float = 5.0
) -> asyncio.Task:
"""Schedule a long-lived background coroutine under supervision.

Expand Down Expand Up @@ -687,7 +693,9 @@ def _create_supervised_task(
self.__background_tasks.append(task)
return task

async def __supervise(self, name, coro_factory, restart_delay) -> None:
async def __supervise(
self, name: str, coro_factory: CoroutineFactory, restart_delay: float
) -> None:
"""Run ``coro_factory`` forever, logging+restarting it on exit/crash."""
while True:
try:
Expand Down
Loading