mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
mastercron status badge
This commit is contained in:
@@ -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 = '<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="' . $id . '" ' . $checked . '></div>';
|
||||
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.<br>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.<br>Seems like your Mastercron isn\'t running!<br>It should run every minute (* * * * *).';
|
||||
$result['status_class'] = 'danger';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result['status'] = 'Not running';
|
||||
$result['status_class'] = 'danger';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,14 +9,24 @@
|
||||
How it works
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
The Cron Manager assists the administrator in managing cron jobs without requiring CLI access.
|
||||
</p>
|
||||
<p class="card-text">
|
||||
To execute cron jobs based on the data below, remove all old cron jobs and create a new one:
|
||||
</p>
|
||||
<div class="main_cronjob">
|
||||
<pre><code id="main_cronjob">* * * * * curl --silent <?php echo base_url(); ?>index.php/cron/run &>/dev/null</code><span data-bs-toggle="tooltip" title="<?php echo lang('copy_to_clipboard'); ?>" onclick='copyCron("main_cronjob")'><i class="copy-icon fas fa-copy"></i></span></pre>
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<p class="card-text">
|
||||
The Cron Manager assists the administrator in managing cron jobs without requiring CLI access.
|
||||
</p>
|
||||
<p class="card-text">
|
||||
To execute cron jobs based on the data below, remove all old cron jobs and create a new one:
|
||||
</p>
|
||||
<div class="main_cronjob">
|
||||
<pre><code id="main_cronjob">* * * * * curl --silent <?php echo base_url(); ?>index.php/cron/run &>/dev/null</code><span data-bs-toggle="tooltip" title="<?php echo lang('copy_to_clipboard'); ?>" onclick='copyCron("main_cronjob")'><i class="copy-icon fas fa-copy"></i></span></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col text-end" id="alert_status">
|
||||
<div class="alert alert-<?php echo $mastercron['status_class'] ?? 'danger'; ?> d-inline-block">
|
||||
Status Master-Cron: <?php echo $mastercron['status'] ?? 'Not running'; ?>
|
||||
</div>
|
||||
<!-- <a class="ms-2 refresh_icon" href="<?php echo site_url('cron'); ?>"><i class="fas fa-sync"></i></a> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -66,7 +76,9 @@
|
||||
} ?></td>
|
||||
<td style="vertical-align: middle;"><button id="<?php echo $cron->id; ?>" class="editCron btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i></button></td>
|
||||
<td style="vertical-align: middle;">
|
||||
<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="<?php echo $cron->id; ?>" <?php if ($cron->enabled ?? '0') { echo 'checked'; } ?>></div>
|
||||
<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="<?php echo $cron->id; ?>" <?php if ($cron->enabled ?? '0') {
|
||||
echo 'checked';
|
||||
} ?>></div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
Reference in New Issue
Block a user