فهرست منبع

Synchro: fixed issue in the counter (deletion of replicas) and improved the behavior in case of an error happening in the underlying process

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1736 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 سال پیش
والد
کامیت
d084850b55
2فایلهای تغییر یافته به همراه27 افزوده شده و 19 حذف شده
  1. 3 1
      synchro/priv_sync_chunk.php
  2. 24 18
      synchro/synchrodatasource.class.inc.php

+ 3 - 1
synchro/priv_sync_chunk.php

@@ -115,11 +115,13 @@ try
 	}
 	if ($oSynchroExec->DoSynchronizeChunk($oLog, $oChange, $iChunkSize))
 	{
+		// The last line MUST follow this convention
 		$oP->p("continue");
 	}
 	else
 	{
-		$oP->p("done!");
+		// The last line MUST follow this convention
+		$oP->p("finished");
 	}
 	$oP->output();
 }

+ 24 - 18
synchro/synchrodatasource.class.inc.php

@@ -2112,7 +2112,8 @@ class SynchroExecution
 		
 		$sSelectTotal  = "SELECT SynchroReplica WHERE sync_source_id = :source_id";
 		$oSetTotal = new DBObjectSet(DBObjectSearch::FromOQL($sSelectTotal), array() /* order by*/, array('source_id' => $this->m_oDataSource->GetKey()));
-		$this->m_oStatLog->Set('stats_nb_replica_total', $oSetTotal->Count());
+		$this->m_iCountAllReplicas = $oSetTotal->Count();
+		$this->m_oStatLog->Set('stats_nb_replica_total', $this->m_iCountAllReplicas);
 
 		$this->m_oStatLog->DBInsertTracked($this->m_oChange);
 	}
@@ -2215,12 +2216,6 @@ class SynchroExecution
 			}
 		}
 
-		// Count the replicas
-		$sSelectAll  = "SELECT SynchroReplica WHERE sync_source_id = :source_id";
-		$oSetAll = new DBObjectSet(DBObjectSearch::FromOQL($sSelectAll), array() /* order by*/, array('source_id' => $this->m_oDataSource->GetKey()));
-		$this->m_iCountAllReplicas = $oSetAll->Count();
-		$this->m_oStatLog->Set('stats_nb_replica_total', $this->m_iCountAllReplicas);
-
 		// Compute and keep track of the limit date taken into account for obsoleting replicas
 		//
 		if ($this->m_oLastFullLoadStartDate == null)
@@ -2361,23 +2356,34 @@ class SynchroExecution
 				$aArguments['step_count'] = $iStepCount;
 				$iStepCount++;
 
-				$this->m_oStatLog->AddTrace("Launching a separate process: step $iStepCount");
-
 				list ($iRes, $aOut) = utils::ExecITopScript('synchro/priv_sync_chunk.php', $aArguments);
 
-				$this->m_oStatLog->AddTrace("The script replied:");
-				foreach ($aOut as $sOut)
+				// Reload the log that has been modified by the processes
+				$this->m_oStatLog->Reload();
+
+				$sLastRes = strtolower(trim(end($aOut)));
+				switch($sLastRes)
 				{
-					$this->m_oStatLog->AddTrace(">>> $sOut");
+				case 'continue':
+					$bContinue = true;
+					break;
+
+				case 'finished':
+					$bContinue = false;
+					break;
+
+				default:
+					$this->m_oStatLog->AddTrace("The script did not reply with the expected keywords:");
+					$aIndentedOut = array();
+					foreach ($aOut as $sOut)
+					{
+						$aIndentedOut[] = "-> $sOut";
+						$this->m_oStatLog->AddTrace(">>> $sOut");
+					}
+					throw new Exception("Encountered an error in an underspinned process:\n".implode("\n", $aIndentedOut));
 				}
-	
-				$sLastRes = strtolower(trim(end($aOut)));
-				$bContinue = ($sLastRes == 'continue');
 			}
 			while ($bContinue);
-			
-			// Reload the log that has been modified by the processes
-			$this->m_oStatLog->Reload();
 		}
 		else
 		{