Пример #1
0
    async def _execute(self, desc: str):
        """
        Generic wrapper for all controller commands.
        State-related preconditions are checked, and errors are handled.

        Args:
            desc (str):
                Human-readable function description, to be used in error messages.
        """
        if await service_status.wait_updating(self.app, wait=False):
            raise exceptions.UpdateInProgress('Update is in progress')

        await asyncio.wait_for(service_status.wait_synchronized(self.app),
                               SYNC_WAIT_TIMEOUT_S)

        try:
            yield

        except exceptions.CommandTimeout as ex:
            # Wrap in a task to not delay the original response
            asyncio.create_task(self._check_connection())
            raise ex

        except Exception as ex:
            LOGGER.debug(f'Failed to execute {desc}: {strex(ex)}')
            raise ex
Пример #2
0
 async def wait_for_sync(self):
     await asyncio.wait_for(
         service_status.wait_synchronized(self.app),
         SYNC_WAIT_TIMEOUT_S)
async def wait_sync(app, client):
    await asyncio.wait_for(service_status.wait_synchronized(app), 5)