summaryrefslogtreecommitdiff
path: root/pages/jobs.inc
blob: 3c0bb3da7565f857f95d8f15e20f2731345257d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?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>
    <?php global $use2023UI; if (!$use2023UI): ?>
    .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;
    }

    <?php endif; ?>

    details[open] summary {
        font-weight: bold;
    }

    <?php if ($use2023UI): ?>
    pre {
        background: var(--palette-4);
        color: var(--palette-6);
        padding: 10px 20px;
        margin-top: 10px;
    }
    <?php else: ?>
    pre {
        background: #000000;
        color: #ffffff;
        padding: 10px 20px;
        margin-top: 10px;
    }
    <?php endif; ?>

    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'; ?>