From de5ccf5908e96c97d1ed0d8d29db92969b7a1165 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Mon, 21 Mar 2011 11:17:42 +0000 Subject: [PATCH] Background processes - API ready for periodicity management SVN:trunk[1137] --- core/asynctask.class.inc.php | 5 +++++ core/backgroundprocess.inc.php | 1 + modules/itop-tickets-1.0.0/model.itop-tickets.php | 11 ++++++++--- webservices/cron.php | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/asynctask.class.inc.php b/core/asynctask.class.inc.php index 7233c5862..f64765747 100644 --- a/core/asynctask.class.inc.php +++ b/core/asynctask.class.inc.php @@ -26,6 +26,11 @@ class ExecAsyncTask implements iBackgroundProcess { + public function GetPeriodicity() + { + return 2; // seconds + } + public function Process($iTimeLimit) { $sOQL = "SELECT AsyncTask WHERE ISNULL(started)"; diff --git a/core/backgroundprocess.inc.php b/core/backgroundprocess.inc.php index bc8d8b1c2..f39182917 100644 --- a/core/backgroundprocess.inc.php +++ b/core/backgroundprocess.inc.php @@ -26,6 +26,7 @@ interface iBackgroundProcess { + public function GetPeriodicity(); public function Process($iUnixTimeLimit); } diff --git a/modules/itop-tickets-1.0.0/model.itop-tickets.php b/modules/itop-tickets-1.0.0/model.itop-tickets.php index 9f5309b65..be2af9e44 100644 --- a/modules/itop-tickets-1.0.0/model.itop-tickets.php +++ b/modules/itop-tickets-1.0.0/model.itop-tickets.php @@ -612,6 +612,11 @@ abstract class ResponseTicket extends Ticket class ProcessSLAResponseTicket implements iBackgroundProcess { + public function GetPeriodicity() + { + return 2; // seconds + } + public function Process($iTimeLimit) { $oMyChange = new CMDBChange(); @@ -622,7 +627,7 @@ class ProcessSLAResponseTicket implements iBackgroundProcess $aReport = array(); $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'new\' AND tto_escalation_deadline <= NOW()')); - while ($oToEscalate = $oSet->Fetch()) + while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch()) { $oToEscalate->ApplyStimulus('ev_timeout'); //$oToEscalate->Set('tto_escalation_deadline', null); @@ -631,7 +636,7 @@ class ProcessSLAResponseTicket implements iBackgroundProcess } $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'assigned\' AND ttr_escalation_deadline <= NOW()')); - while ($oToEscalate = $oSet->Fetch()) + while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch()) { $oToEscalate->ApplyStimulus('ev_timeout'); //$oToEscalate->Set('ttr_escalation_deadline', null); @@ -640,7 +645,7 @@ class ProcessSLAResponseTicket implements iBackgroundProcess } $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'resolved\' AND closure_deadline <= NOW()')); - while ($oToEscalate = $oSet->Fetch()) + while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch()) { $oToEscalate->ApplyStimulus('ev_close'); //$oToEscalate->Set('closure_deadline', null); diff --git a/webservices/cron.php b/webservices/cron.php index 387a09611..6317e827b 100644 --- a/webservices/cron.php +++ b/webservices/cron.php @@ -31,6 +31,10 @@ require_once(APPROOT.'/application/clipage.class.inc.php'); require_once(APPROOT.'/application/startup.inc.php'); + +// Known limitation - the background process periodicity is NOT taken into account + + function CronExec($oP, $aBackgroundProcesses, $bVerbose) { $iStarted = time(); @@ -117,7 +121,7 @@ foreach(get_declared_classes() as $sPHPClass) { $oExecInstance = new $sPHPClass; } - $aBackgroundProcesses[] = $oExecInstance; + $aBackgroundProcesses[$sPHPClass] = $oExecInstance; } }