Improvements and updated documentation

This commit is contained in:
Paolo
2026-06-23 12:33:44 +02:00
parent 5826bf5b70
commit 8126665acd
5 changed files with 46 additions and 30 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ $config['lrt_max_number_single_user'] = 10;
$config['lrt_max_number_system'] = 100;
// Maximum running time in hours for a single LRT before killing it
$config['lrt_max_run_timeout'] = 48;
$config['lrt_max_run_timeout'] = 24;
// List of existing LRT types
$config['lrt_types'] = array('LRTDummy');
@@ -9,7 +9,7 @@ if (!defined("BASEPATH")) exit("No direct script access allowed");
* - This is a Job Queue Worker that gets scheduled LRTs from the queue and executes them
* - Once all the LRTs have been started checks if there are LRTs that are running for too long and kills them
*/
class LongRunTaskExecJob extends JQW_Controller
class LongRunTaskExecJob extends JOB_Controller
{
/**
* Constructor
@@ -72,6 +72,10 @@ class LongRunTaskExecJob extends JQW_Controller
{
// Kill the process with a SIGKILL
exec('kill -9 '.$lrt->pid.' > /dev/null 2>&1');
// Set the LRT as failed
$lrtExecFailedResult = $this->longruntasklib->lrtExecFailed($lrt->jobid);
if (isError($lrtExecFailedResult)) $this->logError(getError(lrtExecFailedResult));
}
}
+3 -3
View File
@@ -21,7 +21,7 @@ class LRTDummy extends LRT_Controller
$this->_jobid = $jobid;
// Get the LRT record related to the provided jobid
$lrtResult = $this->getLrt($jobid);
$lrtResult = $this->getLrt();
// If an error occurred or the record has not been found
if (isError($lrtResult) || !hasData($lrtResult))
@@ -48,7 +48,7 @@ class LRTDummy extends LRT_Controller
{
sleep(1);
// Set the progress
$setProgressResult = $this->setProgress($jobid, (($i + 1) / (int)$input->sleep) * 100);
$setProgressResult = $this->setProgress((($i + 1) / (int)$input->sleep) * 100);
if (isError($setProgressResult))
{
$this->logError($setProgressResult);
@@ -62,7 +62,7 @@ class LRTDummy extends LRT_Controller
$this->logInfo('The user '.$lrt->uid.' slept for '.$input->sleep.' seconds');
// Set the output
$setOutputResult = $this->setOutput($jobid, 'The user '.$lrt->uid.' slept for '.$input->sleep.' seconds');
$setOutputResult = $this->setOutput('The user '.$lrt->uid.' slept for '.$input->sleep.' seconds');
if (isError($setOutputResult))
{
$this->logError($setOutputResult);
+13 -21
View File
@@ -13,7 +13,7 @@ if (!defined("BASEPATH")) exit("No direct script access allowed");
* - Any implementation of a Long Run Task should extends this class to
* properly operate with the LRT system
*/
abstract class LRT_Controller extends JQW_Controller
abstract class LRT_Controller extends JOB_Controller
{
protected $_jobid; // record id for this LRT
@@ -43,20 +43,12 @@ abstract class LRT_Controller extends JQW_Controller
*/
public function __destruct()
{
// Check if the property has been set
if ($this->_jobid == null)
{
$this->logError(
'The method '.get_class($this).'->run must assign the value of the jobid parameter to the property _jobid at the very beginning: $this->_jobid = $jobid;'
);
}
else // If set then
{
// Set the status of this LRT as done
$setStatusResult = $this->longruntasklib->setStatus($this->_jobid, LongRunTaskLib::STATUS_DONE);
// If an error occurred then log it
if (isError($setStatusResult)) $this->logError($setStatusResult);
}
// Sends email to the user
// Set the status and the endtime of this LRT as done
$lrtExecOverResult = $this->longruntasklib->lrtExecOver($this->_jobid);
// If an error occurred then log it
if (isError($lrtExecOverResult)) $this->logError($lrtExecOverResult);
}
//------------------------------------------------------------------------------------------------------------------
@@ -70,25 +62,25 @@ abstract class LRT_Controller extends JQW_Controller
/**
*
*/
protected function getLrt($jobid)
protected function getLrt()
{
return $this->longruntasklib->getLrt($jobid);
return $this->longruntasklib->getLrt($this->_jobid);
}
/**
*
*/
protected function setProgress($jobid, $progress)
protected function setProgress($progress)
{
return $this->longruntasklib->setProgress($jobid, $progress);
return $this->longruntasklib->setProgress($this->_jobid, $progress);
}
/**
*
*/
protected function setOutput($jobid, $output)
protected function setOutput($output)
{
return $this->longruntasklib->setOutuput($jobid, $output);
return $this->longruntasklib->setOutuput($this->_jobid, $output);
}
}
+24 -4
View File
@@ -52,7 +52,7 @@ class LongRunTaskLib extends JobsQueueLib
}
/**
*
* Get all the LRT that are running more then CFG_LRT_MAX_RUN hours
*/
public function getHangingLRTs()
{
@@ -109,6 +109,20 @@ class LongRunTaskLib extends JobsQueueLib
if (isError($updateLrtResult)) return $updateLrtResult;
}
/**
* Set the LRT in the queue as failed
*/
public function lrtExecFailed($jobid)
{
return $this->_ci->JobsQueueModel->update(
$jobid,
array(
'endtime' => 'NOW()',
'status' => self::STATUS_FAILED
)
);
}
//------------------------------------------------------------------------------------------------------------------
// Public methods used by the front end applications (standard controllers/end points, ex. controllers/system/LRTTest.php)
@@ -209,11 +223,17 @@ class LongRunTaskLib extends JobsQueueLib
}
/**
*
* Set the LRT in the queue as successfully ended
*/
public function setStatus($jobid, $status)
public function lrtExecOver($jobid)
{
return $this->_ci->JobsQueueModel->update($jobid, array('status' => $status));
return $this->_ci->JobsQueueModel->update(
$jobid,
array(
'endtime' => 'NOW()',
'status' => self::STATUS_DONE
)
);
}
}