fix(health): use injected cache resource for healthcheck

Inject the live cache resource and ping it directly instead of
rebuilding pool adapters from pools-cache. The container already
constructs the right adapter (pool, multiplexing, none), so the
healthcheck now exercises the actual configured cache.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
loks0n
2026-05-18 13:58:24 +01:00
parent 4f676aac15
commit 2cd422f4c2
@@ -8,12 +8,10 @@ use Appwrite\SDK\ContentType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
use Appwrite\Utopia\Response;
use Utopia\Cache\Adapter\Pool as CachePool;
use Utopia\Config\Config;
use Utopia\Cache\Cache;
use Utopia\Database\Document;
use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\Pools\Group;
class Get extends Action
{
@@ -47,45 +45,32 @@ class Get extends Action
contentType: ContentType::JSON
))
->inject('response')
->inject('pools')
->inject('cache')
->callback($this->action(...));
}
public function action(Response $response, Group $pools): void
public function action(Response $response, Cache $cache): void
{
$output = [];
$failures = [];
$configs = [
'Cache' => Config::getParam('pools-cache'),
];
$checkStart = \microtime(true);
foreach ($configs as $key => $config) {
foreach ($config as $cache) {
try {
$adapter = new CachePool($pools->get($cache));
$checkStart = \microtime(true);
if ($adapter->ping()) {
$output[] = new Document([
'name' => $key . " ($cache)",
'status' => 'pass',
'ping' => \round((\microtime(true) - $checkStart) * 1000),
]);
} else {
$failures[] = $cache;
}
} catch (\Throwable) {
$failures[] = $cache;
}
}
try {
$ok = $cache->ping();
} catch (\Throwable) {
$ok = false;
}
if (!empty($failures)) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Cache failure on: ' . \implode(', ', $failures));
if (!$ok) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Cache failure on: cache');
}
$output[] = new Document([
'name' => 'Cache',
'status' => 'pass',
'ping' => \round((\microtime(true) - $checkStart) * 1000),
]);
$response->dynamic(new Document([
'statuses' => $output,
'total' => \count($output),