From 94d335600cc5082ffba8c2facb28b627fd9b1c2a Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 16 Feb 2021 21:21:11 +0100 Subject: [PATCH] - Added new protected method getOldestJob to JQW_Controller - Added new public method getOldestJob to JobsQueueLib --- application/core/JQW_Controller.php | 13 +++++++++++++ application/libraries/JobsQueueLib.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/application/core/JQW_Controller.php b/application/core/JQW_Controller.php index 72a2a972b..1b78a2a70 100644 --- a/application/core/JQW_Controller.php +++ b/application/core/JQW_Controller.php @@ -47,6 +47,19 @@ abstract class JQW_Controller extends JOB_Controller return $jobs; } + /** + * To get the oldest added job using the given job type + */ + protected function getOldestJob($type) + { + $jobs = $this->jobsqueuelib->getOldestJob($type); + + // If an error occurred then log it in database + if (isError($jobs)) $this->logError(getError($jobs), $type); + + return $jobs; + } + /** * To get all the jobs specified by the given parameters */ diff --git a/application/libraries/JobsQueueLib.php b/application/libraries/JobsQueueLib.php index 0eb7c9b72..a65bb0d29 100644 --- a/application/libraries/JobsQueueLib.php +++ b/application/libraries/JobsQueueLib.php @@ -56,6 +56,19 @@ class JobsQueueLib return $this->_ci->JobsQueueModel->loadWhere(array('status' => self::STATUS_NEW, 'type' => $type)); } + /** + * To get the oldest added jobs using the given job type + */ + public function getOldestJob($type) + { + $this->_ci->JobsQueueModel->resetQuery(); + + $this->_ci->JobsQueueModel->addOrder('creationtime', 'ASC'); + $this->_ci->JobsQueueModel->addLimit('1'); + + return $this->_ci->JobsQueueModel->loadWhere(array('status' => self::STATUS_NEW, 'type' => $type)); + } + /** * To get all the jobs specified by the given parameters */