浏览代码

CRON: report that CRON is already running BEFORE saying that the DB is read-only (re-entrance during an operation done in the background)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2837 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 年之前
父节点
当前提交
c39861f345
共有 1 个文件被更改,包括 9 次插入8 次删除
  1. 9 8
      webservices/cron.php

+ 9 - 8
webservices/cron.php

@@ -310,14 +310,6 @@ if (!UserRights::IsAdministrator())
 	exit -1;
 }
 
-if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
-{
-	$oP->p("A database maintenance is ongoing (read-only mode even for admins).");
-	$oP->Output();
-	exit -1;
-}
-
-
 // Enumerate classes implementing BackgroundProcess
 //
 $aProcesses = array();
@@ -365,6 +357,15 @@ try
 	$oMutex = new iTopMutex('cron.'.$oConfig->GetDBName().'_'.$oConfig->GetDBSubname());
 	if ($oMutex->TryLock())
 	{
+		// Note: testing this now in case some of the background processes forces the read-only mode for a while
+		//       in that case it is better to exit with the check on reentrance (mutex)
+		if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
+		{
+			$oP->p("A database maintenance is ongoing (read-only mode even for admins).");
+			$oP->Output();
+			exit -1;
+		}
+
 		CronExec($oP, $aProcesses, $bVerbose);
 
 		$oMutex->Unlock();