From 3c2dba2b8348fcc880a7838fb58bc741d244af4b Mon Sep 17 00:00:00 2001 From: Luis Hdez Date: Wed, 27 Apr 2016 05:33:34 +0200 Subject: [PATCH] Add methdos for parallel queues --- Resque.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Resque.php b/Resque.php index 2e02473..725c45c 100644 --- a/Resque.php +++ b/Resque.php @@ -151,6 +151,49 @@ public function getQueues() }, \Resque::queues()); } + /** + * Returns an array of queues with its current load + * + * @return array + */ + public function getQueuesLoad($pattern = null) + { + $queues = []; + + foreach (\Resque::queues() as $queue) { + $queues[$queue] = \Resque::size($queue); + } + + return $queues; + } + + /** + * @param $queueKey + * @param $parallelQueues + * + * @return array of queues with its loads + */ + public function getParallelQueueLoads($queueKey, $parallelQueues) + { + for ($i=1; $i <= $parallelQueues; $i++) { + $queues[$queueKey.'-'.$i] = \Resque::size($queueKey.'-'.$i); + } + + return $queues; + } + + /** + * @return string The queue name with less job load + */ + public function getLessLoadedParallelQueue($queueKey, $parallelQueues) + { + $queues = $this->getParallelQueueLoads($queueKey, $parallelQueues); + asort($queues); + $lessLoadedQueue = array_slice($queues, 0, 1); + + return key($lessLoadedQueue); + } + /** * @param $queue *