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 */