Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/314209

Change subject: WIP implement length for Predis and PDO backends
......................................................................

WIP implement length for Predis and PDO backends

Will be useful for monitoring.

TODO: tests.

Bug: T147226
Change-Id: Ib35b3597fc36975e1048a24407b3a52252f9cc13
---
M src/PHPQueue/Backend/PDO.php
M src/PHPQueue/Backend/Predis.php
2 files changed, 29 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/php-queue 
refs/changes/09/314209/1

diff --git a/src/PHPQueue/Backend/PDO.php b/src/PHPQueue/Backend/PDO.php
index e3a620a..a3f3c9a 100644
--- a/src/PHPQueue/Backend/PDO.php
+++ b/src/PHPQueue/Backend/PDO.php
@@ -171,6 +171,22 @@
         return null;
     }
 
+       public function length()
+       {
+               // Get oldest message.
+               $sql = sprintf('SELECT COUNT(*) FROM `%s`', $this->db_table);
+               $sth = $this->getConnection()->prepare($sql);
+
+               // This will be false if the table or collection does not exist
+               if ( !$sth ) {
+                       return 0;
+               }
+
+               $sth->execute();
+
+               return $sth->fetchColumn();
+       }
+
     public function popAtomic($callback) {
         try {
             $this->getConnection()->beginTransaction();
diff --git a/src/PHPQueue/Backend/Predis.php b/src/PHPQueue/Backend/Predis.php
index e74e6a5..c4df0ef 100644
--- a/src/PHPQueue/Backend/Predis.php
+++ b/src/PHPQueue/Backend/Predis.php
@@ -202,6 +202,19 @@
         return json_decode($data, true);
     }
 
+       public function length()
+       {
+               if (!$this->hasQueue()) {
+                       throw new BackendException("No queue specified.");
+               }
+               if ($this->order_key) {
+                       $length = 
$this->getConnection()->zcount(self::FIFO_INDEX, -INF, INF);
+               } else {
+                       $length = 
$this->getConnection()->llen($this->queue_name);
+               }
+               return $length;
+       }
+
     public function popAtomic($callback) {
         if (!$this->hasQueue()) {
             throw new BackendException("No queue specified.");

-- 
To view, visit https://gerrit.wikimedia.org/r/314209
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib35b3597fc36975e1048a24407b3a52252f9cc13
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/php-queue
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to