Sfoglia il codice sorgente

Background processes - API ready for periodicity management

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1137 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 anni fa
parent
commit
c5eb2d7d0b

+ 5 - 0
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)";

+ 1 - 0
core/backgroundprocess.inc.php

@@ -26,6 +26,7 @@
 
 interface iBackgroundProcess
 {
+	public function GetPeriodicity();
 	public function Process($iUnixTimeLimit);
 }
 

+ 8 - 3
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);

+ 5 - 1
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;
 	}
 }