Skip to content

Commit

Permalink
diagnostic endpoints /status & /jobs/status added to API
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Dec 21, 2024
1 parent f246a91 commit b80e62c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
10 changes: 8 additions & 2 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
multiflexi (1.22.0) UNRELEASED; urgency=medium
multiflexi (1.22.1) UNRELEASED; urgency=medium

* diagnostic endpoints /status & /jobs/status added to API

-- vitex <info@vitexsoftware.cz> Sat, 21 Dec 2024 12:11:21 +0100

multiflexi (1.22.0) jammy; urgency=medium

* Artifacts Keeping

-- vitex <info@vitexsoftware.cz> Mon, 09 Dec 2024 23:08:36 +0100
-- vitex <info@vitexsoftware.cz> Sat, 21 Dec 2024 12:10:45 +0100

multiflexi (1.21.1) jammy; urgency=medium

Expand Down
1 change: 1 addition & 0 deletions debian/multiflexi-api.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ src/MultiFlexi/Api/Auth/*.php usr/lib/multiflexi/MultiFlexi/Api/Auth
src/MultiFlexi/Api/Server/*.php usr/lib/multiflexi/MultiFlexi/Api/Server
src/api/config.php usr/share/multiflexi/api
src/api/index.php usr/share/multiflexi/api
src/api/.htaccess usr/share/multiflexi/api
51 changes: 51 additions & 0 deletions src/MultiFlexi/Api/Server/DefaultApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function getApiIndex(ServerRequestInterface $request, ResponseInterface $
$data[] = ['path' => 'companies'];
$data[] = ['path' => 'runtemplates'];
$data[] = ['path' => 'jobs'];
$data[] = ['path' => 'jobs/status'];
$data[] = ['path' => 'topics'];
$data[] = ['path' => 'users'];
$data[] = ['path' => 'credentials'];
Expand Down Expand Up @@ -269,4 +270,54 @@ public function statusSuffixGet(ServerRequestInterface $request, ResponseInterfa

return self::prepareResponse($response, $status, $suffix, 'status');
}

public function getJobsStatus(ServerRequestInterface $request, ResponseInterface $response, string $suffix): ResponseInterface
{
$engine = new \MultiFlexi\Engine();
$pdo = $engine->getPdo();

// Query to get job status information
$query = "
SELECT
COUNT(*) AS total_jobs,
SUM(CASE WHEN exitcode = 0 THEN 1 ELSE 0 END) AS successful_jobs,
SUM(CASE WHEN exitcode != 0 THEN 1 ELSE 0 END) AS failed_jobs,
SUM(CASE WHEN exitcode IS NULL THEN 1 ELSE 0 END) AS incomplete_jobs,
COUNT(DISTINCT app_id) AS total_applications,
SUM(CASE WHEN schedule IS NOT NULL THEN 1 ELSE 0 END) AS repeated_jobs
FROM job
";

$stmt = $pdo->query($query);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);

if($suffix == 'html') {
$status = [

['status' , 'ok?'],
['timestamp', date('c')],
['successful_jobs', (int) $result['successful_jobs']],
['failed_jobs', (int) $result['failed_jobs']],
['incomplete_jobs', (int) $result['incomplete_jobs']],
['total_applications', (int) $result['total_applications']],
['repeated_jobs', (int) $result['repeated_jobs']],
['total_jobs', (int) $result['total_jobs']]

];
} else {
$status = [
'timestamp' => date('c'),
'successful_jobs' => (int) $result['successful_jobs'],
'failed_jobs' => (int) $result['failed_jobs'],
'incomplete_jobs' => (int) $result['incomplete_jobs'],
'total_applications' => (int) $result['total_applications'],
'repeated_jobs' => (int) $result['repeated_jobs'],
'total_jobs' => (int) $result['total_jobs']
];

}


return self::prepareResponse($response, $status, $suffix, 'jobsStatus');
}
}

0 comments on commit b80e62c

Please sign in to comment.