diff --git a/src/handler/action_queue.py b/src/handler/action_queue.py index 7fe6122..48d30fa 100644 --- a/src/handler/action_queue.py +++ b/src/handler/action_queue.py @@ -18,7 +18,7 @@ class ActionQueue: while True: try: if self.queued_actions.empty() and self.idle_action is not None: - self.idle_action_task = asyncio.create_task(self.idle_action[0](*(self.idle_action[1]), **(self.idle_action[2]))) + self.idle_action_task = asyncio.create_task(self.run_action(self.idle_action)) action = await self.queued_actions.get() @@ -26,17 +26,19 @@ class ActionQueue: self.idle_action_task.cancel() self.idle_action_task = None - if action is not None: # If none -> Is idle update - try: - awaitable = action[0](*(action[1]), **(action[2])) - if awaitable is not None: - await awaitable - except Exception as ex: - logging.exception("Something went wrong during execution of action.", ex) + await self.run_action(action) except Exception as ex: logging.exception("Something went wrong in queue task.", ex) + async def run_action(self, action): + if action is None or action[0] is None: + return + + awaitable = action[0](*(action[1]), **(action[2])) + if awaitable is not None: + await awaitable + async def add_action_to_queue(self, action, *args, **kwargs): await self.queued_actions.put((action, args, kwargs))