introducing new way of controling the cronjobs by creating a cron.d-file
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -15,98 +15,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function getNextCronjobs
|
||||
*
|
||||
* checks which cronjobs have to be executed
|
||||
*
|
||||
* @return array array of cron-files which are to be executed
|
||||
*/
|
||||
function getNextCronjobs() {
|
||||
|
||||
$query = "SELECT `id`, `cronfile` FROM `".TABLE_PANEL_CRONRUNS."` WHERE `interval` <> '0' AND `isactive` = '1' AND (";
|
||||
|
||||
$intervals = getIntervalOptions();
|
||||
$x = 0;
|
||||
|
||||
foreach($intervals as $name => $ival) {
|
||||
|
||||
if($name == '0') continue;
|
||||
|
||||
if($x == 0) {
|
||||
$query.= "(UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL ".$ival.")) <= UNIX_TIMESTAMP() AND `interval` = '".$ival."')";
|
||||
} else {
|
||||
$query.= " OR (UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(`lastrun`), INTERVAL ".$ival.")) <= UNIX_TIMESTAMP() AND `interval` = '".$ival."')";
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
$query.= ');';
|
||||
|
||||
$result = Database::query($query);
|
||||
|
||||
$cron_files = array();
|
||||
// Update lastrun-timestamp
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
$cron_files[] = $row['cronfile'];
|
||||
$upd_stmt = Database::prepare("
|
||||
UPDATE `".TABLE_PANEL_CRONRUNS."` SET `lastrun` = UNIX_TIMESTAMP() WHERE `id` = :id;"
|
||||
);
|
||||
Database::pexecute($upd_stmt, array('id' => $row['id']));
|
||||
}
|
||||
|
||||
return $cron_files;
|
||||
}
|
||||
|
||||
function includeCronjobs($debugHandler) {
|
||||
|
||||
global $cronlog;
|
||||
|
||||
$cronjobs = getNextCronjobs();
|
||||
|
||||
$jobs_to_run = array();
|
||||
$cron_path = makeCorrectDir(FROXLOR_INSTALL_DIR.'/scripts/jobs/');
|
||||
|
||||
if ($cronjobs !== false
|
||||
&& is_array($cronjobs)
|
||||
&& isset($cronjobs[0])
|
||||
) {
|
||||
foreach ($cronjobs as $cronjob) {
|
||||
$cron_file = makeCorrectFile($cron_path.$cronjob);
|
||||
if (!file_exists($cron_file)) {
|
||||
$cronlog->logAction(CRON_ACTION, LOG_ERROR, 'Wanted to include cronfile "'.$cron_file.'" but this file does not exist!!!');
|
||||
} else {
|
||||
$jobs_to_run[] = $cron_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $jobs_to_run;
|
||||
}
|
||||
|
||||
|
||||
function getIntervalOptions() {
|
||||
|
||||
global $lng, $cronlog;
|
||||
|
||||
$query = "SELECT DISTINCT `interval` FROM `" . TABLE_PANEL_CRONRUNS . "` ORDER BY `interval` ASC;";
|
||||
$result = Database::query($query);
|
||||
|
||||
$cron_intervals = array();
|
||||
$cron_intervals['0'] = $lng['panel']['off'];
|
||||
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
if (validateSqlInterval($row['interval'])) {
|
||||
$cron_intervals[$row['interval']] = $row['interval'];
|
||||
} else {
|
||||
$cronlog->logAction(CRON_ACTION, LOG_ERROR, "Invalid SQL-Interval ".$row['interval']." detected. Please fix this in the database.");
|
||||
}
|
||||
}
|
||||
|
||||
return $cron_intervals;
|
||||
}
|
||||
|
||||
|
||||
function getCronjobsLastRun() {
|
||||
|
||||
global $lng;
|
||||
|
||||
Reference in New Issue
Block a user