mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-03 16:14:13 +01:00
Cron parallelization
* Setup wait for multiple cron processes * Avoid waiting while tasks must be run
This commit is contained in:
@@ -2044,21 +2044,27 @@ JS
|
||||
if (is_null($oConfig) || ContextTag::Check(ContextTag::TAG_CRON)) {
|
||||
return;
|
||||
}
|
||||
// Use mutex to check if cron is running
|
||||
// Limit the number of cron process to run in parallel
|
||||
$iMaxCronProcess = $oConfig->Get('cron.max_process');
|
||||
$iCount = 1;
|
||||
$iMaxDuration = $oConfig->Get('cron_max_execution_time');
|
||||
$iTimeLimit = time() + $iMaxDuration;
|
||||
do {
|
||||
$bIsRunning = false;
|
||||
// Use all mutexes to check if cron is running
|
||||
for ($i = 0; $i < $iMaxCronProcess; $i++) {
|
||||
$sName = "cron#$i";
|
||||
|
||||
$oMutex = new iTopMutex(
|
||||
'cron'.$oConfig->Get('db_name').$oConfig->Get('db_subname'),
|
||||
$sName.$oConfig->Get('db_name').$oConfig->Get('db_subname'),
|
||||
$oConfig->Get('db_host'),
|
||||
$oConfig->Get('db_user'),
|
||||
$oConfig->Get('db_pwd'),
|
||||
$oConfig->Get('db_tls.enabled'),
|
||||
$oConfig->Get('db_tls.ca')
|
||||
);
|
||||
$iCount = 1;
|
||||
$iStarted = time();
|
||||
$iMaxDuration = $oConfig->Get('cron_max_execution_time');
|
||||
$iTimeLimit = $iStarted + $iMaxDuration;
|
||||
while ($oMutex->IsLocked())
|
||||
{
|
||||
if ($oMutex->IsLocked()) {
|
||||
$bIsRunning = true;
|
||||
SetupLog::Info("Waiting for cron to stop ($iCount)");
|
||||
$iCount++;
|
||||
sleep(1);
|
||||
@@ -2066,8 +2072,12 @@ JS
|
||||
{
|
||||
throw new Exception("Cannot enter $sMode mode, consider stopping the cron temporarily");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
} while ($bIsRunning);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user