HealthCheck class

The controller of Route.health(). It runs the checks at the same time and answers:

  • 200 {"status": "ok", "checks": {"database": "ok"}} when all pass
  • 503 {"status": "fail", "checks": {"database": "fail"}} when one fails

With no checks the answer is 200 {"status": "ok"}. The error text of a failed check is in errors only when APP_ENV is development or local, because it can hold hosts or passwords. It is always given to AppConfig.exceptionHandler.report().

Route.health('/health', checks: <String, HealthCheckFunction>{
  'database': () => QueryBuilder.query('select 1'),
  'cache': HealthCheck.cache(),
});

Constructors

HealthCheck({Map<String, HealthCheckFunction> checks = const <String, HealthCheckFunction>{}, Duration timeout = const Duration(seconds: 5)})
const

Properties

checks → Map<String, HealthCheckFunction>
check name to check
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
timeout → Duration
a check that takes longer fails
final

Methods

handle(DoxRequest req) → Future<DoxResponse>
The route controller.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

cache([String? store]) → HealthCheckFunction
A check that writes a key to the cache and reads it back. store is a store name of AppConfig.cache, default store when null.