Merge branch 'task/lastrun'
This commit is contained in:
commit
2224b61087
15
addjob.php
15
addjob.php
|
@ -64,9 +64,17 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$name = $_POST['name'];
|
$name = $_POST['name'];
|
||||||
$delay = $_POST['delay'];
|
$delay = $_POST['delay'];
|
||||||
$expected = $_POST['expected'];
|
$expected = $_POST['expected'];
|
||||||
|
$eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false;
|
||||||
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
|
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
|
||||||
$nextrun = $nextrunObj->getTimestamp();
|
$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)) {
|
if(!is_numeric($delay)) {
|
||||||
header("location:addjob.php?error=invaliddelay");
|
header("location:addjob.php?error=invaliddelay");
|
||||||
exit;
|
exit;
|
||||||
|
@ -75,7 +83,10 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
header("location:addjob.php?error=invalidnextrun");
|
header("location:addjob.php?error=invalidnextrun");
|
||||||
exit;
|
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 = $db->prepare("INSERT INTO jobs(user, name, url, host, delay, nextrun, expected) VALUES(?, ?, ?, ?, ?, ?, ?)");
|
||||||
$stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun, $expected));
|
$stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun, $expected));
|
||||||
|
|
|
@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `jobs` (
|
||||||
`host` varchar(50) NOT NULL DEFAULT 'localhost',
|
`host` varchar(50) NOT NULL DEFAULT 'localhost',
|
||||||
`delay` int(11) NOT NULL,
|
`delay` int(11) NOT NULL,
|
||||||
`nextrun` int(11) NOT NULL,
|
`nextrun` int(11) NOT NULL,
|
||||||
|
`lastrun` int(11) NOT NULL DEFAULT '-1',
|
||||||
`expected` int(11) NOT NULL DEFAULT '200',
|
`expected` int(11) NOT NULL DEFAULT '200',
|
||||||
PRIMARY KEY (`jobID`)
|
PRIMARY KEY (`jobID`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
19
editjob.php
19
editjob.php
|
@ -42,6 +42,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
||||||
$delay = $jobnameResult[0]['delay'];
|
$delay = $jobnameResult[0]['delay'];
|
||||||
$expected = $jobnameResult[0]['expected'];
|
$expected = $jobnameResult[0]['expected'];
|
||||||
$nextrun = date("d/m/Y H:i:s", $jobnameResult[0]['nextrun']);
|
$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');
|
$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") {
|
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
|
||||||
|
@ -74,8 +75,16 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$delay = $_POST['delay'];
|
$delay = $_POST['delay'];
|
||||||
$host = $_POST['host'];
|
$host = $_POST['host'];
|
||||||
$expected = $_POST['expected'];
|
$expected = $_POST['expected'];
|
||||||
|
$eternal = (isset($_POST['eternal']) && $_POST['eternal'] == true) ? true : false;
|
||||||
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
|
$nextrunObj = DateTime::createFromFormat("d/m/Y H:i:s", $_POST['nextrun']);
|
||||||
$nextrun = $nextrunObj->getTimestamp();
|
$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)) {
|
if(!is_numeric($delay)) {
|
||||||
header("location:editjob.php?jobID=" . $jobID . "&error=invaliddelay");
|
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");
|
header("location:editjob.php?jobID=" . $jobID . "&error=invalidnextrun");
|
||||||
exit;
|
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 = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ?, lastrun = ? WHERE jobID = ?");
|
||||||
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $jobID));
|
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $lastrun, $jobID));
|
||||||
|
|
||||||
header("location:overview.php?message=edited");
|
header("location:overview.php?message=edited");
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -28,6 +28,7 @@ $(document).ready(function() {
|
||||||
if(this.value != "custom") { $("input#delay").val($(this).data("val")); }
|
if(this.value != "custom") { $("input#delay").val($(this).data("val")); }
|
||||||
});
|
});
|
||||||
$('#nextrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } );
|
$('#nextrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } );
|
||||||
|
$('#lastrunselector').datetimepicker( { format: 'DD/MM/YYYY HH:mm:ss' } );
|
||||||
|
|
||||||
$("body").on("click", ".runcron", function() {
|
$("body").on("click", ".runcron", function() {
|
||||||
$("#ajax_loader").show();
|
$("#ajax_loader").show();
|
||||||
|
|
|
@ -56,7 +56,19 @@
|
||||||
</span>
|
</span>
|
||||||
<input type="text" class="form-control" name="nextrun">
|
<input type="text" class="form-control" name="nextrun">
|
||||||
</div>
|
</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"> Eternal
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="expected">Expected exit code</label>
|
<label for="expected">Expected exit code</label>
|
||||||
<input type="text" name="expected" class="form-control" id="host" placeholder="200">
|
<input type="text" name="expected" class="form-control" id="host" placeholder="200">
|
||||||
|
|
|
@ -52,6 +52,18 @@
|
||||||
<input type="text" class="form-control" name="nextrun" value="{{ nextrun }}">
|
<input type="text" class="form-control" name="nextrun" value="{{ nextrun }}">
|
||||||
</div>
|
</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" value="{{ lastrun }}">
|
||||||
|
<span class="input-group-addon">
|
||||||
|
<input type="checkbox" name="eternal" value="true"{% if (lastrun == -1) %} checked{% endif %}> Eternal
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="expected">Expected exit code</label>
|
<label for="expected">Expected exit code</label>
|
||||||
<input type="text" name="expected" class="form-control" id="host" value="{{ expected }}">
|
<input type="text" name="expected" class="form-control" id="host" value="{{ expected }}">
|
||||||
|
|
|
@ -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()));
|
$stmt->execute(array(time()));
|
||||||
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$client = new \GuzzleHttp\Client();
|
$client = new \GuzzleHttp\Client();
|
||||||
|
|
Loading…
Reference in New Issue