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:
@@ -54,33 +54,47 @@ $bCronIsRunning = false;
|
||||
$sLastExecution = null;
|
||||
$processcTimeProcess = 0;
|
||||
$processcTimeStart = 0;
|
||||
if (file_exists(PATH_DATA . "cron")) {
|
||||
$force = false;
|
||||
for ($i = 1; $i <= count($argv) - 1; $i++) {
|
||||
if (strpos($argv[$i], "+force") !== false) {
|
||||
$force = true;
|
||||
unset($argv[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$force) {
|
||||
$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
|
||||
$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;
|
||||
|
||||
$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;
|
||||
unset($argv[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$bCronIsRunning) {
|
||||
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"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes
|
||||
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
|
||||
}
|
||||
|
||||
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 (!$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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -14,23 +14,38 @@ if ($RBAC->userCanAccess("PM_SETUP") != 1) {
|
||||
$bCronIsRunning = false;
|
||||
$sLastExecution = null;
|
||||
$processcTimeProcess = 0;
|
||||
$processcTimeStart = 0;
|
||||
$processcTimeStart = 0;
|
||||
|
||||
if (file_exists( PATH_DATA . "cron" )) {
|
||||
$arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) );
|
||||
$bCronIsRunning = (boolean) ($arrayCron["bCronIsRunning"]);
|
||||
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
|
||||
|
||||
if (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;
|
||||
$processcTimeStart = (isset( $arrayCron["processcTimeStart"] )) ? $arrayCron["processcTimeStart"] : 0;
|
||||
$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"] );
|
||||
|
||||
Reference in New Issue
Block a user