From: Tim Düsterhus Date: Tue, 9 Feb 2016 19:28:41 +0000 (+0100) Subject: Add BackgroundQueueHandler::getRunnableCount() X-Git-Tag: 3.0.0_Beta_1~2051 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=72db011805b4e0dd6df72fefef0324090899f168;p=GitHub%2FWoltLab%2FWCF.git Add BackgroundQueueHandler::getRunnableCount() --- 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(); + } }