From 72db011805b4e0dd6df72fefef0324090899f168 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 9 Feb 2016 20:28:41 +0100 Subject: [PATCH] Add BackgroundQueueHandler::getRunnableCount() --- .../BackgroundQueueHandler.class.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php index 1d300f8e99..c284961a19 100644 --- a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php @@ -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(); + } } -- 2.20.1