2nd draft

This commit is contained in:
Paolo
2026-06-19 13:54:38 +02:00
parent aba680cd52
commit 8c24292195
11 changed files with 391 additions and 80 deletions
@@ -0,0 +1,56 @@
<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");
/**
* - This controller acts as interface of the LongRunTaskLib that contains
* all the needed functionalities to operate with the Long Run Task system
* that is built on top of the Jobs Queue System
* - 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
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// Changes the needed configs for LogLib
$this->LogLibJob->setConfigs(
array(
'dbExecuteUser' => get_class($this),
'requestId' => 'LRT'
)
);
// Loads LongRunTaskLib library
$this->load->library('LongRunTaskLib');
}
/**
*
*/
public function execEmAll()
{
$this->logInfo('Execute long run tasks started');
// Get all the LRTs that is possible to execute now
$lrtsResult = $this->longruntasklib->getLRTs();
if (isError($lrtsResult)) return $lrtsResult;
// For each LRT
foreach (getData($lrtsResult) as $lrt)
{
// 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));
}
$this->logInfo('Execute long run tasks ended');
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");
/**
* Testing LRT to check if the LRT system is working properly
* This will be called by the LongRunTaskExecJob
*/
class LRTDummy extends LRT_Controller
{
/**
*
*/
public function run($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 (isError($lrtResult) || !hasData($lrtResult))
{
$this->logError(getError($lrtResult));
}
else
{
$lrt = getData($lrtResult)[0];
$input = json_decode($lrt->input);
sleep((int)$input->sleep);
$this->setProgress($jobid, 100);
$this->setOutput($jobid, 'I slept for '.$input->sleep.' seconds');
}
}
}
@@ -0,0 +1,56 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
use \stdClass as stdClass;
/**
*
*/
class LRTTest extends Auth_Controller
{
/**
*
*/
public function __construct()
{
parent::__construct(
array(
'index' => 'system/developer:r',
'lrt1min' => 'system/developer:r',
)
);
// Loads LongRunTaskLib library
$this->load->library('LongRunTaskLib');
}
// -----------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Everything has a beginning
*/
public function index()
{
$this->load->view('system/lrtTest.php');
}
/**
*
*/
public function lrt1min()
{
$lrtInput = new stdClass();
$lrtInput->sleep = 1; // Sleep for 1 min
$this->outputJsonSuccess(
$this->longruntasklib->addNewLrtToQueue(
'LRTDummy', // LRT type
getAuthUID(), // UID executer
$lrtInput // LRT input
)
);
}
}