Skip to content

Commit ac84fbb

Browse files
committed
common: Add helper to check if a queue is empty
Signed-off-by: Phoevos Kalemkeris <[email protected]>
1 parent 5837264 commit ac84fbb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cogstack_model_gateway/common/queue.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,11 @@ def consume(self, process_fn: callable):
150150
t.join()
151151
self.channel.stop_consuming()
152152
log.info("Stopped consuming tasks from queue '%s'", self.queue_name)
153+
154+
@with_connection
155+
def is_queue_empty(self):
156+
try:
157+
queue = self.channel.queue_declare(queue=self.queue_name, passive=True)
158+
return queue.method.message_count == 0
159+
except pika.exceptions.ChannelClosed:
160+
return True

0 commit comments

Comments
 (0)