2021-05-27 11:46:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace JeroenED\Webcron\Repository;
|
|
|
|
|
|
|
|
|
|
|
|
use JeroenED\Framework\Repository;
|
|
|
|
|
|
|
|
class Run extends Repository
|
|
|
|
{
|
2021-06-01 13:45:57 +02:00
|
|
|
const FAILED = 'F';
|
|
|
|
const SUCCESS = 'S';
|
|
|
|
const MANUAL = 'M';
|
|
|
|
|
|
|
|
public function getRunsForJob(int $id, $failed = true, $ordered = true): array
|
2021-05-27 11:46:30 +02:00
|
|
|
{
|
|
|
|
$runsSql = "SELECT * FROM run WHERE job_id = :job";
|
|
|
|
$params = [':job' => $id];
|
2021-06-01 13:45:57 +02:00
|
|
|
if ($failed) {
|
|
|
|
$runsSql .= ' AND flags LIKE "%' . Run::FAILED . '%"';
|
2021-05-27 11:46:30 +02:00
|
|
|
}
|
|
|
|
if ($ordered) $runsSql .= ' ORDER by timestamp DESC';
|
|
|
|
$runsStmt = $this->dbcon->prepare($runsSql);
|
|
|
|
$runsRslt = $runsStmt->executeQuery($params);
|
|
|
|
$runs = $runsRslt->fetchAllAssociative();
|
|
|
|
return $runs;
|
|
|
|
}
|
2021-06-01 13:45:57 +02:00
|
|
|
|
|
|
|
public function addRun(int $jobid, string $exitcode, int $starttime, float $runtime, string $output, array $flags): void
|
|
|
|
{
|
|
|
|
// handling of response
|
|
|
|
$addRunSql = 'INSERT INTO run(job_id, exitcode, output, runtime, timestamp,flags) VALUES (:job_id, :exitcode, :output, :runtime, :timestamp, :flags)';
|
|
|
|
$addRunStmt = $this->dbcon->prepare($addRunSql);
|
|
|
|
$addRunStmt->executeQuery([':job_id' => $jobid, ':exitcode' => $exitcode, 'output' => $output, 'runtime' => $runtime, ':timestamp' => $starttime, ':flags' => implode("", $flags)]);
|
|
|
|
}
|
2021-05-27 11:46:30 +02:00
|
|
|
}
|