<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/util/functions.inc'; $history = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/history.json"), true); $running = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/running.json"), true); if (isset($_GET["enqueue"]) && isset($history[(int)$_GET["enqueue"]])) { createJob(explode("(", $history[(int)$_GET["enqueue"]]["name"])[0], $history[(int)$_GET["enqueue"]]["options"]); header("Location: /-/jobs/?enqueued"); die(); } require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; ?> <style> .list-group-item { color: #fff; background-color: #222; border: 1px solid rgba(255, 255, 255, .125); } .list-group-item.disabled { color: #fff; background-color: #222; border-color: rgba(255, 255, 255, .125); opacity: .75; } .list-group-item:hover { background-color: #252525; color: #ddd; } .list-group-item:active, .list-group-item:focus { background-color: #272727; color: #bbb; } details[open] summary { font-weight: bold; } pre { background: #000000; color: #ffffff; padding: 10px 20px; margin-top: 10px; } pre.last { margin-bottom: 0; } .tracking li { margin-bottom: 5px; } .tracking li:nth-last-child(1), .tracking { margin-bottom: 0 !important; } </style> <br> <div class="container"> <div id="page-content"> <h2>Jobs history</h2> <?php if (isset($_GET["enqueued"])): ?> <div class="alert alert-success">Successfully enqueued a new job, it will be run shortly and appear on this page once it has finished.</div> <?php endif; ?> <div class="list-group"> <?php foreach (array_reverse(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs"), function ($i) { return !str_starts_with($i, "."); })) as $index => $file): $item = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs/" . $file), true); ?> <div class="list-group-item disabled" style="list-style: none; display: grid; grid-template-columns: 3fr repeat(2, 1fr);"> <div><?= $item["name"] ?>(<?php foreach ($item["options"] as $name => $value): echo($name . "=" . json_encode($value)); endforeach; ?>)</div> <div><?= timeAgo($item["date"]) ?></div> <div><?php if (isset($running) && $file === $running): ?><span class="text-info">Running</span><?php else: ?><span class="text-warning">Pending</span><?php endif; ?></div> </div> <?php endforeach; ?> <?php foreach ($history as $index => $item): ?> <details class="list-group-item"> <summary style="list-style: none; display: grid; grid-template-columns: 3fr repeat(2, 1fr);"> <div><?= $item["name"] ?></div> <div><?= timeAgo($item["tracking"]["queue"]) ?></div> <div><?php if ($item["completed"]): ?><span class="text-success" style="filter: invert(1) hue-rotate(180deg);">Completed</span><?php else: ?><span class="text-danger" style="filter: invert(1) hue-rotate(180deg);">Failed</span><?php endif; ?></div> </summary> <div class="list-group" style="margin-top: 10px;"> <div class="list-group-item"> <p> <b>Duration:</b> <?= $item["time"] ?>ms · <a href="/-/jobs/?enqueue=<?= $index ?>">Enqueue again</a> <b></b> </p> <b>Console output:</b> <pre><?= $item["output"] ?></pre> <?php if (isset($item["error"])): ?> <b>Server error message:</b> <pre><?= $item["error"] ?></pre> <?php endif; ?> <b>Job lifetime:</b> <ul class="tracking"> <li><b>Queued by PHP</b><br><?= date('M jS Y, G:i:s', strtotime($item["tracking"]["queue"])) ?></li> <?php if (isset($item["tracking"]["pickup"])): ?><li><b>Picked up by the runner</b><br><?= date('M jS Y, G:i:s', strtotime($item["tracking"]["pickup"])) ?></li><?php endif; ?> <?php if (isset($item["tracking"]["start"])): ?><li><b>Started</b><br><?= date('M jS Y, G:i:s', strtotime($item["tracking"]["start"])) ?></li><?php endif; ?> <?php if (isset($item["tracking"]["end"])): ?><li><b><?= $item["completed"] ? "Finished" : "Failed" ?></b><br><?= date('M jS Y, G:i:s', strtotime($item["tracking"]["end"])) ?></li><?php endif; ?> <?php if (isset($item["tracking"]["logged"])): ?><li><b>Tracking logged</b><br><?= date('M jS Y, G:i:s', strtotime($item["tracking"]["logged"])) ?></li><?php endif; ?> </ul> </div> </div> </details> <?php endforeach; ?> </div> </div> </div> <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>