mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
Better output handling
This commit is contained in:
@@ -31,7 +31,7 @@ class LongRunTaskExecJob extends JQW_Controller
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Executes all the new LRTs
|
||||
*/
|
||||
public function execEmAll()
|
||||
{
|
||||
@@ -41,13 +41,14 @@ class LongRunTaskExecJob extends JQW_Controller
|
||||
$lrtsResult = $this->longruntasklib->getLRTs();
|
||||
if (isError($lrtsResult)) return $lrtsResult;
|
||||
|
||||
// For each LRT
|
||||
foreach (getData($lrtsResult) as $lrt)
|
||||
if (hasData($lrtsResult))
|
||||
{
|
||||
// Execute the task
|
||||
$execResult = $this->longruntasklib->executeLrt($lrt);
|
||||
// If an error occurred log it and continue with the next one
|
||||
if (isError($execResult)) $this->logError(getError($execResult));
|
||||
// For each LRT
|
||||
foreach (getData($lrtsResult) as $lrt)
|
||||
{
|
||||
// Execute the task
|
||||
$this->longruntasklib->executeLrt($lrt);
|
||||
}
|
||||
}
|
||||
|
||||
$this->logInfo('Execute long run tasks ended');
|
||||
|
||||
@@ -9,26 +9,69 @@ if (!defined("BASEPATH")) exit("No direct script access allowed");
|
||||
class LRTDummy extends LRT_Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
* Loops on the number of seconds provided by the LRT input
|
||||
* Sleeps every time 1 sec
|
||||
* Writes the progress
|
||||
* Writes the output
|
||||
*/
|
||||
public function run($jobid)
|
||||
{
|
||||
$this->logInfo('Long run tasks '.get_class($this).' started');
|
||||
|
||||
$this->_jobid = $jobid;
|
||||
|
||||
// Get the LRT record related to the provided jobid
|
||||
$lrtResult = $this->getLrt($jobid);
|
||||
|
||||
// If an error occurred or a record has not been found
|
||||
// If an error occurred or the record has not been found
|
||||
if (isError($lrtResult) || !hasData($lrtResult))
|
||||
{
|
||||
$this->logError(getError($lrtResult));
|
||||
$this->logError($lrtResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get the record
|
||||
$lrt = getData($lrtResult)[0];
|
||||
|
||||
// Get and check the input
|
||||
$input = json_decode($lrt->input);
|
||||
sleep((int)$input->sleep);
|
||||
$this->setProgress($jobid, 100);
|
||||
$this->setOutput($jobid, 'I slept for '.$input->sleep.' seconds');
|
||||
if ($input == null)
|
||||
{
|
||||
$this->logError('LRT input is not a valid json');
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = false; // be optimistic
|
||||
|
||||
// Operation
|
||||
for ($i = 0; $i < (int)$input->sleep; $i++)
|
||||
{
|
||||
sleep(1);
|
||||
// Set the progress
|
||||
$setProgressResult = $this->setProgress($jobid, (($i + 1) / (int)$input->sleep) * 100);
|
||||
if (isError($setProgressResult))
|
||||
{
|
||||
$this->logError($setProgressResult);
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If no errors
|
||||
if (!$error)
|
||||
{
|
||||
$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');
|
||||
if (isError($setOutputResult))
|
||||
{
|
||||
$this->logError($setOutputResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->logInfo('Long run tasks '.get_class($this).' ended');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user