feat(nodes): simplify processor loop with an early continue

Prefer an early return/continue to reduce the indentation of the processor loop. Easier to read.

There are other ways to improve its structure but at first glance, they seem to involve changing the logic in scarier ways.
This commit is contained in:
psychedelicious 2024-04-01 07:55:42 +11:00
parent bd9b00a6bf
commit 32d3e4dc5c

View File

@ -127,7 +127,12 @@ class DefaultSessionProcessor(SessionProcessorBase):
# Get the next session to process
self._queue_item = self._invoker.services.session_queue.dequeue()
if self._queue_item is not None:
if self._queue_item is None:
# The queue was empty, wait for next polling interval or event to try again
self._invoker.services.logger.debug("Waiting for next polling interval or event")
poll_now_event.wait(self._polling_interval)
continue
self._invoker.services.logger.debug(f"Executing queue item {self._queue_item.item_id}")
cancel_event.clear()
@ -256,10 +261,6 @@ class DefaultSessionProcessor(SessionProcessorBase):
else:
# Prepare the next invocation
self._invocation = self._queue_item.session.next()
# The session is complete, immediately poll for next session
self._queue_item = None
poll_now_event.set()
else:
# The queue was empty, wait for next polling interval or event to try again
self._invoker.services.logger.debug("Waiting for next polling interval or event")