- Added new protected method getOldestJobs to core/JQW_Controller

- Changed method JQW_Controller->getOldestJob to be a wrapper for getOldestJobs
- Changed method generateJobs to be a wrapper for static method JobsQueueLib::generateJobs
- Removed method JobsQueueLib->getOldestJob
- Added new public method getOldestJobs to JobsQueueLib
- Added new public static method generateJobs to JobsQueueLib
This commit is contained in:
Paolo
2021-07-14 13:02:08 +02:00
parent 54593512af
commit 47326fe9fb
2 changed files with 34 additions and 9 deletions
+22 -2
View File
@@ -58,13 +58,16 @@ class JobsQueueLib
/**
* To get the oldest added jobs using the given job type
* It is eventually specify the maximum amount of jobs to be retrieved
*/
public function getOldestJob($type)
public function getOldestJobs($type, $maxAmount = null)
{
$this->_ci->JobsQueueModel->resetQuery();
$this->_ci->JobsQueueModel->addOrder('creationtime', 'ASC');
$this->_ci->JobsQueueModel->addLimit('1');
// If the maximum amount of jobs to retrieve have been specified
if (is_numeric($maxAmount)) $this->_ci->JobsQueueModel->addLimit($maxAmount);
return $this->_ci->JobsQueueModel->loadWhere(array('status' => self::STATUS_NEW, 'type' => $type));
}
@@ -221,6 +224,23 @@ class JobsQueueLib
return success($results); // otherwise return results in a success object
}
//------------------------------------------------------------------------------------------------------------------
// Public static methods
/**
* Utility method to generate a job with the given parameters and return it inside an array
* ready to be used by addNewJobsToQueue and updateJobsQueue
*/
public static function generateJobs($status, $input)
{
$job = new stdClass();
$job->{self::PROPERTY_STATUS} = $status;
$job->{self::PROPERTY_INPUT} = $input;
return array($job);
}
//------------------------------------------------------------------------------------------------------------------
// Private methods