N°4931 Fix background tasks max duration being set to 3 times its periodicity

This commit is contained in:
Stephen Abello
2022-03-14 09:29:53 +01:00
parent b50ba0ad49
commit 93c6cfffda
2 changed files with 17 additions and 9 deletions

View File

@@ -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',

View File

@@ -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);