Skip to content

Commit

Permalink
Rename _setup_tasks_with_retry and _setup_tasks
Browse files Browse the repository at this point in the history
We'll have to implement retry on our end, so use this as the new normal
naming.
  • Loading branch information
agners committed Sep 4, 2024
1 parent 2ab5604 commit cad00c4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(
self._fabric_id_hex: str | None = None
self._wifi_credentials_set: bool = False
self._thread_credentials_set: bool = False
self._setup_node_with_retry_tasks = dict[int, asyncio.Task]()
self._setup_node_tasks = dict[int, asyncio.Task]()
self._nodes_in_ota: set[int] = set()
self._node_last_seen_on_mdns: dict[int, float] = {}
self._nodes: dict[int, MatterNodeData] = {}
Expand Down Expand Up @@ -231,7 +231,7 @@ async def stop(self) -> None:
if self._aiozc:
await self._aiozc.async_close()
# Ensure any in-progress setup tasks are cancelled
for task in self._setup_node_with_retry_tasks.values():
for task in self._setup_node_tasks.values():
task.cancel()

# shutdown the sdk device controller
Expand Down Expand Up @@ -770,7 +770,7 @@ async def remove_node(self, node_id: int) -> None:

LOGGER.info("Removing Node ID %s.", node_id)

if task := self._setup_node_with_retry_tasks.pop(node_id, None):
if task := self._setup_node_tasks.pop(node_id, None):
task.cancel()

# shutdown any existing subscriptions
Expand Down Expand Up @@ -1276,11 +1276,12 @@ def _get_next_node_id(self) -> int:
self.server.storage.set(DATA_KEY_LAST_NODE_ID, next_node_id, force=True)
return next_node_id

async def _setup_node(
async def _setup_node_try_once(
self,
node_logger: logging.LoggerAdapter,
node_id: int,
) -> None:
"""Handle set-up of subscriptions and interview (if needed) for known/discovered node."""
node_data = self._nodes[node_id]
log_timers: dict[int, asyncio.TimerHandle] = {}
is_thread_node = (
Expand Down Expand Up @@ -1390,16 +1391,15 @@ async def log_node_long_setup(time_start: float) -> None:
if is_thread_node:
self._thread_node_setup_throttle.release()

async def _setup_node_with_retry(self, node_id: int) -> None:
"""Handle set-up of subscriptions and interview (if needed) for known/discovered node."""
async def _setup_node(self, node_id: int) -> None:
if node_id not in self._nodes:
raise NodeNotExists(f"Node {node_id} does not exist.")

node_logger = self.get_node_logger(LOGGER, node_id)

while True:
try:
await self._setup_node(node_logger, node_id)
await self._setup_node_try_once(node_logger, node_id)
break
except (NodeNotResolving, NodeInterviewFailed, ChipStackError):
if (
Expand All @@ -1419,12 +1419,12 @@ async def _setup_node_with_retry(self, node_id: int) -> None:

def _setup_node_create_task(self, node_id: int) -> asyncio.Task | None:
"""Create a task for setting up a node with retry."""
if node_id in self._setup_node_with_retry_tasks:
if node_id in self._setup_node_tasks:
node_logger = self.get_node_logger(LOGGER, node_id)
node_logger.debug("Setup task exists already for this Node")
return None
task = asyncio.create_task(self._setup_node_with_retry(node_id))
self._setup_node_with_retry_tasks[node_id] = task
task = asyncio.create_task(self._setup_node(node_id))
self._setup_node_tasks[node_id] = task
return task

def _handle_endpoints_removed(self, node_id: int, endpoints: Iterable[int]) -> None:
Expand Down

0 comments on commit cad00c4

Please sign in to comment.