From 126c3a38de309743575574eae4c419062d14a053 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 26 Jan 2024 15:55:55 +0000 Subject: [PATCH 1/2] Add threshold --- app/controllers/api/health.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 618362b0af..3b34f2cdec 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -709,16 +709,23 @@ App::get('/v1/health/queue/failed/:name') Event::MIGRATIONS_QUEUE_NAME, Event::HAMSTER_CLASS_NAME ]), 'The name of the queue') + ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->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_QUEUE) ->inject('response') ->inject('queue') - ->action(function (string $name, Response $response, Connection $queue) { + ->action(function (string $name, int|string $threshold, Response $response, Connection $queue) { + $threshold = \intval($threshold); + $client = new Client($name, $queue); $failed = $client->countFailedJobs(); + if ($failed >= $threshold) { + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue failed jobs threshold hit. Current size is {$failed} and threshold is {$threshold}."); + } + $response->dynamic(new Document([ 'size' => $failed ]), Response::MODEL_HEALTH_QUEUE); }); From 91e625cfc2e34d3079791fde61e971380d9d3b66 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 26 Jan 2024 18:04:06 +0000 Subject: [PATCH 2/2] chore: linter --- app/controllers/api/health.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 3b34f2cdec..3b875f7156 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -718,7 +718,7 @@ App::get('/v1/health/queue/failed/:name') ->inject('queue') ->action(function (string $name, int|string $threshold, Response $response, Connection $queue) { $threshold = \intval($threshold); - + $client = new Client($name, $queue); $failed = $client->countFailedJobs();