diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Base.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Base.php index 72fdf801b5..d5cf87a0cd 100644 --- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Base.php +++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Base.php @@ -10,17 +10,11 @@ abstract class Base extends Action { use HTTP; - protected function assertQueueThreshold(int $size, int $threshold): void + protected function assertQueueThreshold(int $size, int $threshold, bool $failed = false): void { if ($size >= $threshold) { - throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); - } - } - - protected function assertFailedQueueThreshold(int $failed, int $threshold): void - { - if ($failed >= $threshold) { - throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue failed jobs threshold hit. Current size is {$failed} and threshold is {$threshold}."); + $context = $failed ? 'failed jobs' : 'jobs'; + throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue {$context} threshold hit. Current value is {$size} and threshold is {$threshold}."); } } } diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php index 652b1a504c..9832e5d89f 100644 --- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php +++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php @@ -121,7 +121,7 @@ class Get extends Base }; $failed = $queue->getSize(failed: true); - $this->assertFailedQueueThreshold($failed, $threshold); + $this->assertQueueThreshold($failed, $threshold, true); $response->dynamic(new Document(['size' => $failed]), Response::MODEL_HEALTH_QUEUE); } diff --git a/src/Appwrite/Platform/Modules/Health/Services/Http.php b/src/Appwrite/Platform/Modules/Health/Services/Http.php index f1196fa5e8..54c6f9ad6d 100644 --- a/src/Appwrite/Platform/Modules/Health/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Health/Services/Http.php @@ -8,6 +8,7 @@ use Appwrite\Platform\Modules\Health\Http\Health\Certificate\Get as GetCertifica use Appwrite\Platform\Modules\Health\Http\Health\DB\Get as GetDB; use Appwrite\Platform\Modules\Health\Http\Health\Get as GetHealth; use Appwrite\Platform\Modules\Health\Http\Health\PubSub\Get as GetPubSub; +use Appwrite\Platform\Modules\Health\Http\Health\Queue\Audits\Get as GetQueueAudits; use Appwrite\Platform\Modules\Health\Http\Health\Queue\Builds\Get as GetQueueBuilds; use Appwrite\Platform\Modules\Health\Http\Health\Queue\Certificates\Get as GetQueueCertificates; use Appwrite\Platform\Modules\Health\Http\Health\Queue\Databases\Get as GetQueueDatabases; @@ -45,6 +46,7 @@ class Http extends Service $this->addAction(GetStorage::getName(), new GetStorage()); $this->addAction(GetAntivirus::getName(), new GetAntivirus()); + $this->addAction(GetQueueAudits::getName(), new GetQueueAudits()); $this->addAction(GetQueueWebhooks::getName(), new GetQueueWebhooks()); $this->addAction(GetQueueLogs::getName(), new GetQueueLogs()); $this->addAction(GetQueueCertificates::getName(), new GetQueueCertificates()); diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 4b7062dc22..a5a6bf29f7 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -370,6 +370,32 @@ class HealthCustomServerTest extends Scope return []; } + public function testAuditsSuccess(): array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/audits', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['size']); + $this->assertLessThan(100, $response['body']['size']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/audits?threshold=0', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(503, $response['headers']['status-code']); + + return []; + } + public function testStorageLocalSuccess(): array { /**