]> git.ipfire.org Git - pbs.git/commitdiff
messages: Add __len__ to Queue class
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Oct 2022 14:19:52 +0000 (14:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Oct 2022 14:19:52 +0000 (14:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/messages.py

index 747385d341b5c52a461155f1e6a658e353d64daa..084637b7ef44fc8f4ee2f3f655748dd32c5ec619 100644 (file)
@@ -205,6 +205,19 @@ class Queue(base.Object):
 
                return iter(messages)
 
+       def __len__(self):
+               res = self.db.get("""
+                       SELECT
+                               COUNT(*) AS length
+                       FROM
+                               messages
+                       WHERE
+                               sent_at IS NULL
+                       """,
+               )
+
+               return res.length
+
        def enqueue(self, message, priority=None):
                """
                        Enqueues a new message