Allowing non-awaitable idle actions as well

This commit is contained in:
Maximilian Giller 2024-01-30 20:31:32 +01:00
parent da780894d0
commit 91648b739f

View file

@ -18,7 +18,7 @@ class ActionQueue:
while True: while True:
try: try:
if self.queued_actions.empty() and self.idle_action is not None: 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() action = await self.queued_actions.get()
@ -26,17 +26,19 @@ class ActionQueue:
self.idle_action_task.cancel() self.idle_action_task.cancel()
self.idle_action_task = None self.idle_action_task = None
if action is not None: # If none -> Is idle update await self.run_action(action)
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)
except Exception as ex: except Exception as ex:
logging.exception("Something went wrong in queue task.", 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): async def add_action_to_queue(self, action, *args, **kwargs):
await self.queued_actions.put((action, args, kwargs)) await self.queued_actions.put((action, args, kwargs))