Merge branch 'task/lastrun'

This commit is contained in:
Jeroen De Meerleer 2019-05-24 18:47:32 +02:00
commit 2224b61087
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
7 changed files with 57 additions and 7 deletions

View File

@ -64,9 +64,17 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$delay = $_POST['delay'];
$expected = $_POST['expected'];
$eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false;
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
$nextrun = $nextrunObj->getTimestamp();
if (!$eternal) {
$lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']);
$lastrun = $lastrunObj->getTimestamp();
} else {
$lastrun = -1;
}
if(!is_numeric($delay)) {
header("location:addjob.php?error=invaliddelay");
exit;
@ -75,7 +83,10 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
header("location:addjob.php?error=invalidnextrun");
exit;
}
if(!is_numeric($lastrun)) {
header("location:addjob.php?error=invalidlastrun");
exit;
}
$stmt = $db->prepare("INSERT INTO jobs(user, name, url, host, delay, nextrun, expected) VALUES(?, ?, ?, ?, ?, ?, ?)");
$stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun, $expected));

View File

@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `jobs` (
`host` varchar(50) NOT NULL DEFAULT 'localhost',
`delay` int(11) NOT NULL,
`nextrun` int(11) NOT NULL,
`lastrun` int(11) NOT NULL DEFAULT '-1',
`expected` int(11) NOT NULL DEFAULT '200',
PRIMARY KEY (`jobID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -42,6 +42,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") {
$delay = $jobnameResult[0]['delay'];
$expected = $jobnameResult[0]['expected'];
$nextrun = date("d/m/Y H:i:s", $jobnameResult[0]['nextrun']);
$lastrun = ($jobnameResult[0]['lastrun'] == -1) ? -1 : date("d/m/Y H:i:s", $jobnameResult[0]['lastrun']);
$loader = new Twig_Loader_Filesystem('templates');
@ -60,7 +61,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") {
}
echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "expected" => $expected, 'nextrun' => $nextrun, "jobID" => $jobID, "error" => $error));
echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "expected" => $expected, 'nextrun' => $nextrun, 'lastrun' => $lastrun, "jobID" => $jobID, "error" => $error));
}
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
@ -74,8 +75,16 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
$delay = $_POST['delay'];
$host = $_POST['host'];
$expected = $_POST['expected'];
$eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false;
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
$nextrun = $nextrunObj->getTimestamp();
if (!$eternal) {
$lastrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['lastrun']);
$lastrun = $lastrunObj->getTimestamp();
} else {
$lastrun = -1;
}
if(!is_numeric($delay)) {
header("location:editjob.php?jobID=" . $jobID . "&error=invaliddelay");
@ -85,10 +94,14 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
header("location:editjob.php?jobID=" . $jobID . "&error=invalidnextrun");
exit;
}
if(!is_numeric($lastrun)) {
header("location:editjob.php?jobID=" . $jobID . "&error=invalidlastrun");
exit;
}
$stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ? WHERE jobID = ?");
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $jobID));
$stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ?, lastrun = ? WHERE jobID = ?");
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $lastrun, $jobID));
header("location:overview.php?message=edited");
exit;

View File

@ -28,6 +28,7 @@ $(document).ready(function() {
if(this.value != "custom") { $("input#delay").val($(this).data("val")); }
});
$('#nextrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } );
$('#lastrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } );
$("body").on("click", ".runcron", function() {
$("#ajax_loader").show();

View File

@ -56,7 +56,19 @@
</span>
<input type="text" class="form-control" name="nextrun">
</div>
</div>
</div>
<div class="form-group">
<label for="lastrun">Last run</label>
<div class="input-group date" id="lastrunselector">
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
<input type="text" class="form-control" name="lastrun">
<span class="input-group-addon">
<input type="checkbox" name="eternal" value="true">&nbsp;Eternal
</span>
</div>
</div>
<div class="form-group">
<label for="expected">Expected exit code</label>
<input type="text" name="expected" class="form-control" id="host" placeholder="200">

View File

@ -52,6 +52,18 @@
<input type="text" class="form-control" name="nextrun" value="{{ nextrun }}">
</div>
</div>
<div class="form-group">
<label for="lastrun">Last run</label>
<div class="input-group date" id="lastrunselector">
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
<input type="text" class="form-control" name="lastrun" value="{{ lastrun }}">
<span class="input-group-addon">
<input type="checkbox" name="eternal" value="true"{% if (lastrun == -1) %} checked{% endif %}>&nbsp;Eternal
</span>
</div>
</div>
<div class="form-group">
<label for="expected">Expected exit code</label>
<input type="text" name="expected" class="form-control" id="host" value="{{ expected }}">

View File

@ -67,7 +67,7 @@ if (file_exists("cache/get-services.trigger")) {
}
}
$stmt = $db->prepare('SELECT jobID, url, host, delay, nextrun, expected FROM jobs WHERE nextrun <= ?');
$stmt = $db->prepare('SELECT * FROM jobs WHERE nextrun <= ? and (nextrun <= lastrun OR lastrun = -1)');
$stmt->execute(array(time()));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$client = new \GuzzleHttp\Client();