Skip to content

Commit

Permalink
Set short timeout on first Redis pop
Browse files Browse the repository at this point in the history
The previous code was always triggering a long timeout, even when
executed with the exit_on_empty_queues option. This commit uses a shorter
timeout until the first time the queues are empty.

This is really useful for tests, as most of them are obviously launched with
the exit_on_empty_queues option set: it saves 5 seconds for each test relying
on Redis queues.
  • Loading branch information
liZe committed Jan 7, 2021
1 parent fbdbc41 commit 8952deb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion azafea/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ def run(self) -> None:
queues = tuple(self.config.queues.keys())
log.debug('{%s} Pulling from event queues: %s', self.name, queues)

timeout = 0.1

while self._continue:
result = self._redis.brpop(queues, timeout=5)
result = self._redis.brpop(queues, timeout=timeout)

if result is None:
if self.config.main.exit_on_empty_queues:
log.info('{%s} Event queues are empty, exiting', self.name)
break

log.debug('{%s} Pulled nothing from the queues and timed out', self.name)
timeout = 5
continue

queue, value = result
Expand Down

0 comments on commit 8952deb

Please sign in to comment.