Last update:
August 26, 2024
Health Checks in VirtoCommerce Platform¶
VirtoCommerce platform supports health checks through ASP.NET Core middlewares. To ensure robustness and reliability, this article covers two primary aspects:
Module health checks¶
To add health checks to your modules:
-
Create a class that inherits from the
IHealthCheck
interface and implement it. For example:CatalogHealthCheck.cspublic class CatalogHealthCheck : IHealthCheck { public Task<HealthCheckResult> CheckHealthAsync( HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken)) { var healthCheckResultHealthy = true; if (healthCheckResultHealthy) { return Task.FromResult( HealthCheckResult.Healthy("A healthy result.")); } return Task.FromResult( new HealthCheckResult(context.Registration.FailureStatus, "An unhealthy result.")); } }
-
Register the created health checks in the service collection. For example, in your module's initialization:
Now you can check your platform by getting a response from /health
endpoint:
Docker integration¶
For Docker environments, you can use the built-in HEALTHCHECK
directive to monitor the status of your application. For example: