BUG-00000 "El script cron.php puede ser ejecutado varias veces" SOLVED

Issue:
    El script cron.php puede ser ejecutado varias veces
Cause:
    El archivo bandera "cron" trabaja bien en Windows y no asi en Linux
Solution:
    - Se ha agregado nuevas validaciones para entornos Linux
      Ejemplo: ps -fea | grep cron.php | grep -v grep
    - Se ha mejorado el codigo
This commit is contained in:
Victor Saisa Lopez
2014-08-29 12:15:33 -04:00
parent c46400ef36
commit 8503ed8ab5
4 changed files with 130 additions and 137 deletions

View File

@@ -54,8 +54,10 @@ $bCronIsRunning = false;
$sLastExecution = null;
$processcTimeProcess = 0;
$processcTimeStart = 0;
if (file_exists(PATH_DATA . "cron")) {
$force = false;
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
for ($i = 1; $i <= count($argv) - 1; $i++) {
if (strpos($argv[$i], "+force") !== false) {
$force = true;
@@ -63,24 +65,36 @@ if (file_exists(PATH_DATA . "cron")) {
break;
}
}
if (!$force) {
$arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
if (!$force && file_exists(PATH_DATA . "cron")) {
//Windows flag
//Get data of cron file
$arrayCron = unserialize(trim(file_get_contents(PATH_DATA . "cron")));
$bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]);
$sLastExecution = $arrayCron["sLastExecution"];
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? intval($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
} else {
G::rm_dir(PATH_DATA . "cron");
}
}
if ($bCronIsRunning && $processcTimeStart != 0) {
if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
//Cron finished his execution for some reason
$bCronIsRunning = false;
if (!$force && $osIsLinux) {
//Linux flag
//Check if cron it's running
exec("ps -fea | grep cron.php | grep -v grep", $arrayOutput);
if (count($arrayOutput) > 1) {
$bCronIsRunning = true;
}
}
if (!$bCronIsRunning) {
//if (!$force && $bCronIsRunning && $processcTimeStart != 0) {
// if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
// //Cron finished his execution for some reason
// $bCronIsRunning = false;
// }
//}
if ($force || !$bCronIsRunning) {
//Start cron
$arrayCron = array("bCronIsRunning" => "1", "sLastExecution" => date("Y-m-d H:i:s"));
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));

View File

@@ -176,20 +176,6 @@ if (! defined ('PATH_HOME')) {
// G::loadClass('pmScript');
// //default values
// $bCronIsRunning = false;
// $sLastExecution = '';
// if ( file_exists(PATH_DATA . 'cron') ) {
// $aAux = unserialize( trim( @file_get_contents(PATH_DATA . 'cron')) );
// $bCronIsRunning = (boolean)$aAux['bCronIsRunning'];
// $sLastExecution = $aAux['sLastExecution'];
// }
// else {
// //if not exists the file, just create a new one with current date
// @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' =>
// '1', 'sLastExecution' => date('Y-m-d H:i:s'))));
// }
print "PATH_HOME: " . PATH_HOME . "\n";
print "PATH_DB: " . PATH_DB . "\n";
print "PATH_CORE: " . PATH_CORE . "\n";
@@ -312,10 +298,6 @@ else {
processWorkspace ();
}
// finally update the file
// @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' =>
// '0', 'sLastExecution' => date('Y-m-d H:i:s'))));
function processWorkspace()
{
global $sLastExecution;

View File

@@ -107,20 +107,6 @@ require_once 'classes/model/AppEvent.php';
require_once 'classes/model/CaseScheduler.php';
// G::loadClass('pmScript');
// //default values
// $bCronIsRunning = false;
// $sLastExecution = '';
// if ( file_exists(PATH_DATA . 'cron') ) {
// $aAux = unserialize( trim( @file_get_contents(PATH_DATA . 'cron')) );
// $bCronIsRunning = (boolean)$aAux['bCronIsRunning'];
// $sLastExecution = $aAux['sLastExecution'];
// }
// else {
// //if not exists the file, just create a new one with current date
// @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' =>
// '1', 'sLastExecution' => date('Y-m-d H:i:s'))));
// }
print "PATH_HOME: " . PATH_HOME . "\n";
print "PATH_DB: " . PATH_DB . "\n";
print "PATH_CORE: " . PATH_CORE . "\n";
@@ -244,10 +230,6 @@ else {
processWorkspace ();
}
// finally update the file
// @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' =>
// '0', 'sLastExecution' => date('Y-m-d H:i:s'))));
function processWorkspace()
{
global $sLastExecution;

View File

@@ -16,21 +16,36 @@ $sLastExecution = null;
$processcTimeProcess = 0;
$processcTimeStart = 0;
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
if (file_exists(PATH_DATA . "cron")) {
$arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) );
//Windows flag
//Get data of cron file
$arrayCron = unserialize(trim(file_get_contents(PATH_DATA . "cron")));
$bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]);
$sLastExecution = $arrayCron["sLastExecution"];
$processcTimeProcess = (isset( $arrayCron["processcTimeProcess"] )) ? intval( $arrayCron["processcTimeProcess"] ) : 10;
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
}
if ($bCronIsRunning && $processcTimeStart != 0) {
if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
//Cron finished his execution for some reason
$bCronIsRunning = false;
if ($osIsLinux) {
//Linux flag
//Check if cron it's running
exec("ps -fea | grep cron.php | grep -v grep", $arrayOutput);
if (count($arrayOutput) > 0) {
$bCronIsRunning = true;
}
}
//if ($bCronIsRunning && $processcTimeStart != 0) {
// if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
// //Cron finished his execution for some reason
// $bCronIsRunning = false;
// }
//}
//Data
$c = new Configurations();
$configPage = $c->getConfiguration( "cronList", "pageSize", null, $_SESSION["USER_LOGGED"] );