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,8 +54,10 @@ $bCronIsRunning = false;
|
|||||||
$sLastExecution = null;
|
$sLastExecution = null;
|
||||||
$processcTimeProcess = 0;
|
$processcTimeProcess = 0;
|
||||||
$processcTimeStart = 0;
|
$processcTimeStart = 0;
|
||||||
if (file_exists(PATH_DATA . "cron")) {
|
|
||||||
$force = false;
|
$force = false;
|
||||||
|
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
|
||||||
|
|
||||||
for ($i = 1; $i <= count($argv) - 1; $i++) {
|
for ($i = 1; $i <= count($argv) - 1; $i++) {
|
||||||
if (strpos($argv[$i], "+force") !== false) {
|
if (strpos($argv[$i], "+force") !== false) {
|
||||||
$force = true;
|
$force = true;
|
||||||
@@ -63,24 +65,36 @@ if (file_exists(PATH_DATA . "cron")) {
|
|||||||
break;
|
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"]);
|
$bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]);
|
||||||
$sLastExecution = $arrayCron["sLastExecution"];
|
$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;
|
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
|
||||||
} else {
|
|
||||||
G::rm_dir(PATH_DATA . "cron");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ($bCronIsRunning && $processcTimeStart != 0) {
|
if (!$force && $osIsLinux) {
|
||||||
if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
|
//Linux flag
|
||||||
//Cron finished his execution for some reason
|
//Check if cron it's running
|
||||||
$bCronIsRunning = false;
|
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
|
//Start cron
|
||||||
$arrayCron = array("bCronIsRunning" => "1", "sLastExecution" => date("Y-m-d H:i:s"));
|
$arrayCron = array("bCronIsRunning" => "1", "sLastExecution" => date("Y-m-d H:i:s"));
|
||||||
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
||||||
|
|||||||
@@ -176,20 +176,6 @@ if (! defined ('PATH_HOME')) {
|
|||||||
|
|
||||||
// G::loadClass('pmScript');
|
// 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_HOME: " . PATH_HOME . "\n";
|
||||||
print "PATH_DB: " . PATH_DB . "\n";
|
print "PATH_DB: " . PATH_DB . "\n";
|
||||||
print "PATH_CORE: " . PATH_CORE . "\n";
|
print "PATH_CORE: " . PATH_CORE . "\n";
|
||||||
@@ -312,10 +298,6 @@ else {
|
|||||||
processWorkspace ();
|
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()
|
function processWorkspace()
|
||||||
{
|
{
|
||||||
global $sLastExecution;
|
global $sLastExecution;
|
||||||
|
|||||||
@@ -107,20 +107,6 @@ require_once 'classes/model/AppEvent.php';
|
|||||||
require_once 'classes/model/CaseScheduler.php';
|
require_once 'classes/model/CaseScheduler.php';
|
||||||
// G::loadClass('pmScript');
|
// 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_HOME: " . PATH_HOME . "\n";
|
||||||
print "PATH_DB: " . PATH_DB . "\n";
|
print "PATH_DB: " . PATH_DB . "\n";
|
||||||
print "PATH_CORE: " . PATH_CORE . "\n";
|
print "PATH_CORE: " . PATH_CORE . "\n";
|
||||||
@@ -244,10 +230,6 @@ else {
|
|||||||
processWorkspace ();
|
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()
|
function processWorkspace()
|
||||||
{
|
{
|
||||||
global $sLastExecution;
|
global $sLastExecution;
|
||||||
|
|||||||
@@ -16,21 +16,36 @@ $sLastExecution = null;
|
|||||||
$processcTimeProcess = 0;
|
$processcTimeProcess = 0;
|
||||||
$processcTimeStart = 0;
|
$processcTimeStart = 0;
|
||||||
|
|
||||||
|
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
|
||||||
|
|
||||||
if (file_exists(PATH_DATA . "cron")) {
|
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"]);
|
$bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]);
|
||||||
$sLastExecution = $arrayCron["sLastExecution"];
|
$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;
|
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bCronIsRunning && $processcTimeStart != 0) {
|
if ($osIsLinux) {
|
||||||
if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
|
//Linux flag
|
||||||
//Cron finished his execution for some reason
|
//Check if cron it's running
|
||||||
$bCronIsRunning = false;
|
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
|
//Data
|
||||||
$c = new Configurations();
|
$c = new Configurations();
|
||||||
$configPage = $c->getConfiguration( "cronList", "pageSize", null, $_SESSION["USER_LOGGED"] );
|
$configPage = $c->getConfiguration( "cronList", "pageSize", null, $_SESSION["USER_LOGGED"] );
|
||||||
|
|||||||
Reference in New Issue
Block a user