mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 16:32:20 +00:00
Long Run Tasks first draft
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Configs for the Long Run Tasks
|
||||
*/
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
// Maximum LRTs for a single user in parallel
|
||||
$config['lrt_max_number_single_user'] = 10;
|
||||
|
||||
// Maximum LRTs for the whole system in parallel
|
||||
$config['lrt_max_number_system'] = 100;
|
||||
|
||||
// Maximum running time in hours for a single LRT before killing it
|
||||
$config['lrt_max_run_timeout'] = 48;
|
||||
|
||||
// List of existing LRT types
|
||||
$config['lrt_types'] = array('LRTDocumentConvertion');
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
if (!defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
/**
|
||||
* Long Run Task
|
||||
*
|
||||
* 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 an abstract class that provide basic functionalities,
|
||||
* it has to be extended to broaden its logic
|
||||
*/
|
||||
abstract class LRT_Controller extends JQW_Controller
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Changes the needed configs for LogLib
|
||||
$this->LogLibJob->setConfigs(
|
||||
array(
|
||||
'dbExecuteUser' => 'LRTs queue system',
|
||||
'requestId' => 'LTR'
|
||||
)
|
||||
);
|
||||
|
||||
// Loads LongRunTaskLib library
|
||||
$this->load->library('LongRunTaskLib');
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Protected methods
|
||||
|
||||
/**
|
||||
* Get the oldest added LRTs to the queue having status = new
|
||||
*/
|
||||
protected function getLRTs()
|
||||
{
|
||||
$lrts = $this->longruntasklib->getLRTs();
|
||||
|
||||
// If an error occurred then log it in database
|
||||
if (isError($lrts)) $this->logError(getError($lrts));
|
||||
|
||||
return $lrts;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function addNewLRTsToQueue($type, $lrts)
|
||||
{
|
||||
$result = $this->longruntasklib->addNewLRTsToQueue($type, $lrts);
|
||||
|
||||
// If an error occurred then log it in database
|
||||
if (isError($result)) $this->logError(getError($result), $type);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to generate a job with the given parameters and return it inside an array
|
||||
* ready to be used by addNewJobsToQueue and updateJobsQueue
|
||||
*/
|
||||
protected function generateJobs($status, $input)
|
||||
{
|
||||
return JobsQueueLib::generateJobs($status, $input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
use \stdClass as stdClass;
|
||||
|
||||
/**
|
||||
* Library that contains all the needed functionalities to operate with the Jobs Queue System
|
||||
*/
|
||||
@@ -24,12 +26,12 @@ class JobsQueueLib
|
||||
const PROPERTY_END_TIME = 'endtime';
|
||||
const PROPERTY_ERROR = 'error';
|
||||
|
||||
private $_ci; // CI instance
|
||||
protected $_ci; // CI instance
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($authenticate = true)
|
||||
public function __construct()
|
||||
{
|
||||
// Gets CI instance
|
||||
$this->_ci =& get_instance();
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Library that contains all the needed functionalities to operate with the Long Run Tasks
|
||||
*/
|
||||
class LongRunTaskLib extends JobsQueueLib
|
||||
{
|
||||
const CFG_LRT_MAX_NUMBER_SYSTEM = 'lrt_max_number_system';
|
||||
const CFG_LRT_TYPES = 'lrt_types';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Loads the Long Run Tasks configs
|
||||
$this->_ci->config->load('lrt');
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* Get the oldest added LRTs to the queue having status = new
|
||||
* The maximum number of returned queued LRTs is limited by:
|
||||
* number of currently running LRTs - maximum allowed number of LRTs for the system
|
||||
*/
|
||||
public function getLRTs()
|
||||
{
|
||||
// Get all the running LRTs
|
||||
$runningLrtsResult = $this->getJobsByTypeStatus($this->_ci->config->item(self::CFG_LRT_TYPES)), JobsQueueLib::STATUS_RUNNING);
|
||||
|
||||
if (isError($runningLrtsResult)) return $runningLrtsResult;
|
||||
|
||||
// The number of the currently running LRTs - the maximum LRTs for the system
|
||||
$max_number_of_lrts = $this->_ci->config->item(self::CFG_LRT_MAX_NUMBER_SYSTEM)) - count(getData($runningLrtsResult));
|
||||
|
||||
// Get the oldest LRTs added to the queue
|
||||
return $this->getOldestJobs($this->_ci->config->item(self::CFG_LRT_TYPES)), $max_number_of_lrts);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function addNewLRTsToQueue($type, $lrts)
|
||||
{
|
||||
return $this->addNewJobsToQueue($type, $lrts);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public static methods
|
||||
|
||||
/**
|
||||
* Utility method to generate a LTR with the given parameters and return it inside an array
|
||||
* ready to be used by addNewLRTsToQueue
|
||||
*/
|
||||
public static function generateLtrs($status, $input)
|
||||
{
|
||||
return self::generateJobs($status, $input);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user