express-service-readiness-middleware
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -33,2 +33,11 @@ import { NextFunction, Request, Response } from "express"; | ||
} | ||
/** Dependencies Health interface */ | ||
export interface IDependenciesHealth { | ||
/** indicates whether all dependencies are healthy */ | ||
allDependenciesHealthy: boolean; | ||
/** indicates whether all critical dependencies are healthy */ | ||
allCriticalDependenciesHealthy: boolean; | ||
/** health information about all dependencies */ | ||
dependencies: IDependencyHealth[]; | ||
} | ||
/** Dependency health interface */ | ||
@@ -62,3 +71,3 @@ export interface IDependencyHealth { | ||
*/ | ||
export declare const checkDependenciesHealth: (dependencies: IDependency[]) => Promise<IDependencyHealth[]>; | ||
export declare const checkDependenciesHealth: (dependencies: IDependency[]) => Promise<IDependenciesHealth>; | ||
/** | ||
@@ -65,0 +74,0 @@ * Set a logger |
@@ -49,2 +49,4 @@ "use strict"; | ||
const promises = []; | ||
let allDependenciesHealthy = true; | ||
let allCriticalDependenciesHealthy = true; | ||
for (const dependency of dependencies) { | ||
@@ -57,10 +59,20 @@ promises.push(checkDependencyHealth(dependency)); | ||
const promiseResult = promiseResults[i]; | ||
const healthy = promiseResult.status === 'fulfilled' && promiseResult.value; | ||
dependenciesHealth.push({ | ||
name: dependency.name, | ||
data: dependency.data, | ||
healthy: promiseResult.status === 'fulfilled' && promiseResult.value, | ||
healthy, | ||
critical: dependency.critical | ||
}); | ||
if (!healthy) { | ||
allDependenciesHealthy = false; | ||
if (dependency.critical) | ||
allCriticalDependenciesHealthy = false; | ||
} | ||
} | ||
return dependenciesHealth; | ||
return { | ||
allDependenciesHealthy, | ||
allCriticalDependenciesHealthy, | ||
dependencies: dependenciesHealth | ||
}; | ||
}; | ||
@@ -67,0 +79,0 @@ exports.checkDependenciesHealth = checkDependenciesHealth; |
{ | ||
"name": "express-service-readiness-middleware", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "This module provides express middleware for determining whether routes are exposed based on service critical dependency health.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -26,3 +26,3 @@ | ||
createReadinessMiddleware, | ||
criticalDependenciesReady | ||
criticalDependenciesReady, | ||
setLogger | ||
@@ -48,5 +48,17 @@ } = require('express-service-readiness-middleware') | ||
^^ would output: | ||
{ | ||
"name": "dependency-one", "critical": true, "data": { "connectionString": "protocol:://{user}:{password}/test", }, "healthy": true} | ||
*/ | ||
{ | ||
"allDependenciesHealthy": true, | ||
"allCriticalDependenciesHealthy": true, | ||
"dependencies": [ | ||
{ | ||
name": "dependency-one", | ||
"critical": true, | ||
"data": { | ||
"connectionString": "protocol:://{user}:{password}/test", }, | ||
"healthy": true | ||
} | ||
} | ||
] | ||
} | ||
*/ | ||
@@ -86,6 +98,25 @@ // check whether all critical dependencies are ready | ||
The `checkDependenciesHealth` will check all dependencies health and return a result. `isHealthy` will be used if defined on a dependency otherwise it will fallback to `isReady`. | ||
The `checkDependenciesHealth` will check all dependencies health and return a result. `isHealthy` will be used if defined on a dependency otherwise it will fall back to `isReady`. | ||
```js | ||
const health = await checkDependenciesHealth(dependencies) | ||
const health = await checkDependenciesHealth(dependencies) | ||
console.log(JSON.stringify(health, null, 2)) | ||
/* | ||
^^ would output: | ||
{ | ||
"allDependenciesHealthy": true, | ||
"allCriticalDependenciesHealthy": true, | ||
"dependencies": [ | ||
{ | ||
name": "dependency-one", | ||
"critical": true, | ||
"data": { | ||
"connectionString": "protocol:://{user}:{password}/test", }, | ||
"healthy": true | ||
} | ||
} | ||
] | ||
} | ||
*/ | ||
``` | ||
@@ -92,0 +123,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22492
266
159