1
0
Fork 0
mirror of synced 2024-09-30 17:26:48 +13:00

Merge pull request #7499 from appwrite/feat-add-queue-threshold

Add threshold to queue failed health endpoint
This commit is contained in:
Christy Jacob 2024-01-26 22:13:27 +04:00 committed by GitHub
commit 5d2d74e64d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
});