Add BackgroundQueueHandler::getRunnableCount()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 9 Feb 2016 19:28:41 +0000 (20:28 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 9 Feb 2016 19:28:41 +0000 (20:28 +0100)
wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php

index 1d300f8e99d58876f1c97b5262c9eff1d5ce6ebb..c284961a195ca78714d76e58d37867dae0240df3 100644 (file)
@@ -196,4 +196,23 @@ class BackgroundQueueHandler extends SingletonFactory {
                        $statement->execute([ $row['jobID'] ]);
                }
        }
+       
+       /**
+        * Returns how many items are due.
+        * Note: Do not rely on the return value being correct, some other process may
+        * have modified the queue contents, before this method returns. Think of it as an
+        * approximation to know whether you should spend some time to clear the queue.
+        * 
+        * @return      int
+        */
+       public function getRunnableCount() {
+               $sql = "SELECT  COUNT(*)
+                       FROM    wcf".WCF_N."_background_job
+                       WHERE           status = ?
+                               AND     time <= ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute([ 'ready', TIME_NOW ]);
+               
+               return $statement->fetchSingleColumn();
+       }
 }