N°1342 cron task validity checks :

* checks are now made one by one
* new class_exists() test

SVN:trunk[5371]
This commit is contained in:
Pierre Goiffon
2018-02-27 15:20:55 +00:00
parent 3b3f4044cb
commit d8c141b1c9

View File

@@ -169,14 +169,39 @@ function CronExec($oP, $aProcesses, $bVerbose)
// Reset the next planned execution to take into account new settings // Reset the next planned execution to take into account new settings
$oSearch = new DBObjectSearch('BackgroundTask'); $oSearch = new DBObjectSearch('BackgroundTask');
/** @var DBObjectSet $oTasks */
$oTasks = new DBObjectSet($oSearch); $oTasks = new DBObjectSet($oSearch);
while ($oTask = $oTasks->Fetch()) while (
/** @var BackgroundTask $oTask */
$oTask = $oTasks->Fetch())
{ {
$sTaskClass = $oTask->Get('class_name'); if ($oTask->Get('status') != 'active')
$oRefClass = new ReflectionClass($sTaskClass); {
continue;
}
$oNow = new DateTime(); $oNow = new DateTime();
if ($oRefClass->implementsInterface('iScheduledProcess') && (($oTask->Get('status') != 'active') || ($oTask->Get('next_run_date') > $oNow->format('Y-m-d H:i:s')))) if ($oTask->Get('next_run_date') > $oNow->format('Y-m-d H:i:s'))
{ {
continue;
}
$sTaskClass = $oTask->Get('class_name');
if (!class_exists($sTaskClass)) // we could also try/catch when instanciating ReflectionClass, but sometimes old recipes are good too ;)
{
$oP->p("ERROR : the background task was paused because it references the non existing class '$sTaskClass'");
$oTask->Set('status', 'paused');
$oTask->DBUpdate();
continue;
}
$oRefClass = new ReflectionClass($sTaskClass);
if (!$oRefClass->implementsInterface('iScheduledProcess'))
{
continue;
}
if ($bVerbose) if ($bVerbose)
{ {
$oP->p("Resetting the next run date for $sTaskClass"); $oP->p("Resetting the next run date for $sTaskClass");
@@ -186,7 +211,6 @@ function CronExec($oP, $aProcesses, $bVerbose)
$oTask->Set('next_run_date', $oNextOcc->format('Y-m-d H:i:s')); $oTask->Set('next_run_date', $oNextOcc->format('Y-m-d H:i:s'));
$oTask->DBUpdate(); $oTask->DBUpdate();
} }
}
$iCronSleep = MetaModel::GetConfig()->Get('cron_sleep'); $iCronSleep = MetaModel::GetConfig()->Get('cron_sleep');