mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°4931 Fix background tasks max duration being set to 3 times its periodicity
This commit is contained in:
@@ -496,6 +496,14 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => true,
|
||||
],
|
||||
'cron_task_max_execution_time' => [
|
||||
'type' => 'integer',
|
||||
'description' => 'Backround tasks will use this value (integer) multiplicated by its periodicity (in seconds) as max duration per cron execution. 0 is unlimited time',
|
||||
'default' => 0,
|
||||
'value' => 0,
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
],
|
||||
'cron_sleep' => [
|
||||
'type' => 'integer',
|
||||
'description' => 'Duration (seconds) before cron.php checks again if something must be done',
|
||||
|
||||
@@ -106,18 +106,18 @@ function RunTask(BackgroundTask $oTask, $iTimeLimit)
|
||||
$oTask->Set('system_user', utils::GetCurrentUserName());
|
||||
$oTask->Set('running', 1);
|
||||
$oTask->DBUpdate();
|
||||
// Time in seconds allowed to the task
|
||||
$iCurrTimeLimit = $iTimeLimit;
|
||||
// Compute allowed time
|
||||
if ($oRefClass->implementsInterface('iScheduledProcess'))
|
||||
if ($oRefClass->implementsInterface('iScheduledProcess') === false)
|
||||
{
|
||||
$iCurrTimeLimit = $iTimeLimit;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Periodic task, allow only 3x the period
|
||||
$iCurrTimeLimit = time() + $oProcess->GetPeriodicity() * 3;
|
||||
if ($iCurrTimeLimit > $iTimeLimit)
|
||||
// Periodic task, allow only X times ($iMaxTaskExecutionTime) its periodicity (GetPeriodicity())
|
||||
$iMaxTaskExecutionTime = MetaModel::GetConfig()->Get('cron_task_max_execution_time');
|
||||
$iTaskLimit = time() + $oProcess->GetPeriodicity() * $iMaxTaskExecutionTime;
|
||||
// If our proposed time limit is less than cron limit, and cron_task_max_execution_time is > 0
|
||||
if ($iTaskLimit < $iTimeLimit && $iMaxTaskExecutionTime > 0)
|
||||
{
|
||||
$iCurrTimeLimit = $iTimeLimit;
|
||||
$iCurrTimeLimit = $iTaskLimit;
|
||||
}
|
||||
}
|
||||
$sMessage = $oProcess->Process($iCurrTimeLimit);
|
||||
|
||||
Reference in New Issue
Block a user