diff --git a/application/controllers/Cron.php b/application/controllers/Cron.php index 74cb08693..af0c80d66 100644 --- a/application/controllers/Cron.php +++ b/application/controllers/Cron.php @@ -32,6 +32,10 @@ class cron extends CI_Controller { $data['page_title'] = "Cron Manager"; $data['crons'] = $this->cron_model->get_crons(); + $mastercron = array(); + $mastercron = $this->get_mastercron_status(); + $data['mastercron'] = $mastercron; + $this->load->view('interface_assets/header', $data); $this->load->view('cron/index'); $this->load->view('interface_assets/footer', $footerData); @@ -105,6 +109,10 @@ class cron extends CI_Controller { $this->cron_model->set_status($cron->id, $status); $this->cronexpression = null; } + + $datetime = new DateTime("now", new DateTimeZone('UTC')); + $datetime = $datetime->format('Ymd H:i:s'); + $this->optionslib->update('mastercron_last_run', $datetime , 'no'); } public function editDialog() { @@ -217,4 +225,38 @@ class cron extends CI_Controller { $htmlret = '
'; return $htmlret; } + + private function get_mastercron_status() { + $warning_timelimit_seconds = 120; // yellow - warning please check + $error_timelimit_seconds = 600; // red - "not running" + + $result = array(); + + $last_run = $this->optionslib->get_option('mastercron_last_run') ?? null; + + if ($last_run != null) { + $timestamp_last_run = DateTime::createFromFormat('Ymd H:i:s', $last_run, new DateTimeZone('UTC')); + $now = new DateTime(); + $diff = $now->getTimestamp() - $timestamp_last_run->getTimestamp(); + + if ($diff >= 0 && $diff <= $warning_timelimit_seconds) { + $result['status'] = 'OK'; + $result['status_class'] = 'success'; + } else { + if ($diff <= $error_timelimit_seconds) { + $result['status'] = 'Last run occurred more than ' . $warning_timelimit_seconds . ' seconds ago.
Please check your master cron! It should run every minute (* * * * *).'; + $result['status_class'] = 'warning'; + } else { + $result['status'] = 'Last run occurred more than ' . ($error_timelimit_seconds / 60) . ' minutes ago.
Seems like your Mastercron isn\'t running!
It should run every minute (* * * * *).'; + $result['status_class'] = 'danger'; + } + } + } else { + $result['status'] = 'Not running'; + $result['status_class'] = 'danger'; + } + + return $result; + } + } diff --git a/application/views/cron/index.php b/application/views/cron/index.php index e51d9c817..640548de5 100644 --- a/application/views/cron/index.php +++ b/application/views/cron/index.php @@ -9,14 +9,24 @@ How it works
-

- The Cron Manager assists the administrator in managing cron jobs without requiring CLI access. -

-

- To execute cron jobs based on the data below, remove all old cron jobs and create a new one: -

-
-
* * * * * curl --silent index.php/cron/run &>/dev/null
+
+
+

+ The Cron Manager assists the administrator in managing cron jobs without requiring CLI access. +

+

+ To execute cron jobs based on the data below, remove all old cron jobs and create a new one: +

+
+
* * * * * curl --silent index.php/cron/run &>/dev/null
+
+
+
+
+ Status Master-Cron: +
+ +
@@ -66,7 +76,9 @@ } ?> -
enabled ?? '0') { echo 'checked'; } ?>>
+
enabled ?? '0') { + echo 'checked'; + } ?>>