<?php



require_once(__DIR__ . "/../src/load.php");



use Idearia\Logger;

Logger::$log_level = 'info';

Logger::$write_log = true;

Logger::$log_dir = __DIR__ . "/../logs2";

Logger::$log_file_name = basename(__FILE__, ".php");

Logger::$log_file_extension = 'log';

Logger::$log_file_append = true;

Logger::$print_log = false;



$transport = new IntDataTransport(INTDB_HOST, INTDB_USER, INTDB_PASS, INTDB_DATABASE);





$data = [];

if ($tasks = $transport->select("job_queue_jobs", ["pipeline", "payload", "is_reserved", "is_buried", "attempts"], [])) {

	foreach ($tasks as $task) {

		$payload = json_decode($task["payload"], 1);

		$itemAction = $payload["itemAction"] ?? "-";

		$pipeline = $task["pipeline"];

		$data[$pipeline] = $data[$pipeline] ?? [];

		$data[$pipeline][$itemAction] = $data[$pipeline][$itemAction] ?? ["executing" => 0, "failed" => 0, "queue" => 0];



		if ($task["is_reserved"]) {

			$data[$pipeline][$itemAction]["executing"]++;

		} elseif ($task["is_buried"]) {

			$data[$pipeline][$itemAction]["failed"]++;

		} else {

			$data[$pipeline][$itemAction]["queue"]++;

		}

	}

}



?>

<style>

	table, tr, th, tr {

		border-collapse: collapse;

	}

	td, th {

		text-align: center;

		padding: 10px;

		border: 1px solid;

	}

</style>

<table>

<tr>

	<th>Pipeline</th>

	<th>Action</th>

	<th>Queue</th>

	<th>Executing</th>

	<th>Failed</th>

</tr>

<?php foreach ($data as $pipeline => $actions) { ?>

	<?php foreach ($actions as $action => $item) { ?>

		<tr>

			<td><?= $pipeline ?></td>

			<td><?= $action ?></td>

			<td><?= $item["queue"] ?></td>

			<td><?= $item["executing"] ?></td>

			<td><?= $item["failed"] ?></td>

		</tr>

	<?php } ?>

<?php } ?>

</table>