Skip to main content

Recipes

Registering an active check with a timeout

import { getFeatureInstance, HealthcheckStatus, type IQHealthcheck } from '@quik/core';

const healthcheck = getFeatureInstance<IQHealthcheck>('IQHealthcheck');

healthcheck.registerCheck('cache', async () => {
// return true/false or a HealthcheckStatus value
return HealthcheckStatus.OK;
}, { timeoutMs: 1000, onErrorStatus: HealthcheckStatus.DEGRADED });

await healthcheck.runChecks();

registerCheck accepts a function returning void/boolean/HealthcheckStatus. A void/true result maps to OK, false maps to UNREADY. runChecks() executes every registered check, applying timeoutMs (per-check or the healthcheck.timeoutMilliseconds default) and falling back to options.onTimeoutStatus/onErrorStatus when a check times out or throws.

Marking status manually

healthcheck.pending('worker'); // default state after register()
healthcheck.degraded('worker');
healthcheck.down('worker');
healthcheck.unready('worker');
healthcheck.ok('worker');

Reading aggregated status

const statuses = healthcheck.all(); // Record<string, HealthcheckStatus>
const workerStatus = healthcheck.status('worker');

GET /ready (registered by QHealthcheckRoute) aggregates every registered item's status with priority down > unready > pending > degraded > ready, and returns 503 unless every item resolves to ready.