Skip to content

Commit

Permalink
Update health.php
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed Jan 24, 2024
1 parent dc2107f commit 867bc02
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions app/controllers/api/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@
use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;

const QUEUE_NAMES = [
'Database' => Event::DATABASE_QUEUE_NAME,
'Delete' => Event::DELETE_QUEUE_NAME,
'Audit' => Event::AUDITS_QUEUE_NAME,
'Mail' => Event::MAILS_QUEUE_NAME,
'Function' => Event::FUNCTIONS_QUEUE_NAME,
'Usage' => Event::USAGE_QUEUE_NAME,
'Webhook' => Event::WEBHOOK_QUEUE_NAME,
'Certificate' => Event::CERTIFICATES_QUEUE_NAME,
'Build' => Event::BUILDS_QUEUE_NAME,
'Messaging' => Event::MESSAGING_QUEUE_NAME,
'Migration' => Event::MIGRATIONS_QUEUE_NAME,
'Hamster' => Event::HAMSTER_QUEUE_NAME,
];

App::get('/v1/health')
->desc('Get HTTP')
->groups(['api', 'health'])
Expand Down Expand Up @@ -710,18 +695,31 @@
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
->label('sdk.namespace', 'health')
->label('sdk.method', 'getFailedJobs')
->param('queueName', '', new WhiteList(array_keys(QUEUE_NAMES)), 'The name of the queue')
->param('queueName', '', new WhiteList([
Event::DATABASE_QUEUE_NAME,
Event::DELETE_QUEUE_NAME,
Event::AUDITS_QUEUE_NAME,
Event::MAILS_QUEUE_NAME,
Event::FUNCTIONS_QUEUE_NAME,
Event::USAGE_QUEUE_NAME,
Event::WEBHOOK_CLASS_NAME,
Event::CERTIFICATES_QUEUE_NAME,
Event::BUILDS_QUEUE_NAME,
Event::MESSAGING_QUEUE_NAME,
Event::MIGRATIONS_QUEUE_NAME,
Event::HAMSTER_CLASS_NAME
]), 'The name of the queue')
->label('sdk.description', '/docs/references/health/get-failed-queue-jobs.md')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_HEALTH_FAILED_JOBS)
->inject('response')
->inject('queue')
->action(function (string $queueName, Response $response, Connection $queue) {
$client = new Client(QUEUE_NAMES[$queueName], $queue);
$failed = $client->sumFailedJobs(); //TODO: Replace with countFailedJobs() when new version is ready
$client = new Client($queueName, $queue);
$failed = $client->countFailedJobs();

$response->dynamic(new Document([ 'failed' => $failed]), Response::MODEL_HEALTH_FAILED_JOBS);
$response->dynamic(new Document(['failed' => $failed]), Response::MODEL_HEALTH_FAILED_JOBS);
});

App::get('/v1/health/stats') // Currently only used internally
Expand Down

0 comments on commit 867bc02

Please sign in to comment.