Merge pull request #343 from eis-os/simplify_master_cronjob
Simplify master cronjob
This commit is contained in:
@@ -20,7 +20,6 @@ define('MASTER_CRONJOB', 1);
|
|||||||
include_once dirname(dirname(__FILE__)) . '/lib/cron_init.php';
|
include_once dirname(dirname(__FILE__)) . '/lib/cron_init.php';
|
||||||
|
|
||||||
$jobs_to_run = array();
|
$jobs_to_run = array();
|
||||||
$lastrun_update = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check for --help
|
* check for --help
|
||||||
@@ -45,7 +44,6 @@ for ($x = 1; $x < count($argv); $x++) {
|
|||||||
if (isset($argv[$x])) {
|
if (isset($argv[$x])) {
|
||||||
// --force
|
// --force
|
||||||
if (strtolower($argv[$x]) == '--force') {
|
if (strtolower($argv[$x]) == '--force') {
|
||||||
$crontasks = makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/jobs/cron_tasks.php');
|
|
||||||
// really force re-generating of config-files by
|
// really force re-generating of config-files by
|
||||||
// inserting task 1
|
// inserting task 1
|
||||||
inserttask('1');
|
inserttask('1');
|
||||||
@@ -53,8 +51,7 @@ for ($x = 1; $x < count($argv); $x++) {
|
|||||||
inserttask('4');
|
inserttask('4');
|
||||||
// also regenerate cron.d-file
|
// also regenerate cron.d-file
|
||||||
inserttask('99');
|
inserttask('99');
|
||||||
addToQueue($jobs_to_run, $crontasks);
|
addToQueue($jobs_to_run, 'tasks');
|
||||||
$lastrun_update['tasks'] = $crontasks;
|
|
||||||
}
|
}
|
||||||
elseif (strtolower($argv[$x]) == '--debug') {
|
elseif (strtolower($argv[$x]) == '--debug') {
|
||||||
define('CRON_DEBUG_FLAG', 1);
|
define('CRON_DEBUG_FLAG', 1);
|
||||||
@@ -62,9 +59,8 @@ for ($x = 1; $x < count($argv); $x++) {
|
|||||||
// --[cronname]
|
// --[cronname]
|
||||||
elseif (substr(strtolower($argv[$x]), 0, 2) == '--') {
|
elseif (substr(strtolower($argv[$x]), 0, 2) == '--') {
|
||||||
if (strlen($argv[$x]) > 3) {
|
if (strlen($argv[$x]) > 3) {
|
||||||
$cronfile = makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/jobs/cron_'.substr(strtolower($argv[$x]), 2).'.php');
|
$cronname = substr(strtolower($argv[$x]), 2);
|
||||||
addToQueue($jobs_to_run, $cronfile);
|
addToQueue($jobs_to_run, $cronname);
|
||||||
$lastrun_update[substr(strtolower($argv[$x]), 2)] = $cronfile;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,8 +72,9 @@ $cronlog->setCronDebugFlag(defined('CRON_DEBUG_FLAG'));
|
|||||||
if (count($jobs_to_run) > 0) {
|
if (count($jobs_to_run) > 0) {
|
||||||
// include all jobs we want to execute
|
// include all jobs we want to execute
|
||||||
foreach ($jobs_to_run as $cron) {
|
foreach ($jobs_to_run as $cron) {
|
||||||
updateLastRunOfCron($lastrun_update, $cron);
|
updateLastRunOfCron($cron);
|
||||||
require_once $cron;
|
$cronfile = getCronFile($cron);
|
||||||
|
require_once $cronfile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,21 +92,22 @@ checkLastGuid();
|
|||||||
include_once FROXLOR_INSTALL_DIR . '/lib/cron_shutdown.php';
|
include_once FROXLOR_INSTALL_DIR . '/lib/cron_shutdown.php';
|
||||||
|
|
||||||
// -- helper function
|
// -- helper function
|
||||||
function addToQueue(&$jobs_to_run, $cronfile = null, $checkExists = true) {
|
function getCronFile($cronname) {
|
||||||
if ($checkExists == false || ($checkExists && file_exists($cronfile))) {
|
return makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/jobs/cron_'.$cronname.'.php');
|
||||||
if (!in_array($cronfile, $jobs_to_run)) {
|
}
|
||||||
array_unshift($jobs_to_run, $cronfile);
|
|
||||||
|
function addToQueue(&$jobs_to_run, $cronname) {
|
||||||
|
if (!in_array($cronname, $jobs_to_run)) {
|
||||||
|
$cronfile = getCronFile($cronname);
|
||||||
|
if (file_exists($cronfile)) {
|
||||||
|
array_unshift($jobs_to_run, $cronname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLastRunOfCron($update_arr, $cronfile) {
|
function updateLastRunOfCron($cronname) {
|
||||||
foreach ($update_arr as $cron => $cronf) {
|
|
||||||
if ($cronf == $cronfile) {
|
|
||||||
$upd_stmt = Database::prepare("
|
$upd_stmt = Database::prepare("
|
||||||
UPDATE `".TABLE_PANEL_CRONRUNS."` SET `lastrun` = UNIX_TIMESTAMP() WHERE `cronfile` = :cron;
|
UPDATE `".TABLE_PANEL_CRONRUNS."` SET `lastrun` = UNIX_TIMESTAMP() WHERE `cronfile` = :cron;
|
||||||
");
|
");
|
||||||
Database::pexecute($upd_stmt, array('cron' => $cron));
|
Database::pexecute($upd_stmt, array('cron' => $cronname));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user