express-service-readiness-middleware
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -48,20 +48,14 @@ "use strict"; | ||
const dependenciesHealth = []; | ||
const promises = []; | ||
for (const dependency of dependencies) { | ||
let healthy = false; | ||
try { | ||
const healthyFunc = dependency.isHealthy ? dependency.isHealthy : dependency.isReady; | ||
healthy = await healthyFunc(); | ||
if (healthy) { | ||
informationLogger?.log(`critical dependency '${dependency.name}' is healthy`); | ||
} | ||
informationLogger?.log(`critical dependency '${dependency.name}' is not healthy`); | ||
} | ||
catch (err) { | ||
// @ts-ignore | ||
informationLogger?.log(`An error occurred while checking health for dependency '${dependencyStateItem.name}', error: ${err.message || err}`); | ||
} | ||
promises.push(checkDependencyHealth(dependency)); | ||
} | ||
const promiseResults = await Promise.allSettled(promises); | ||
for (let i = 0; i < dependencies.length; i++) { | ||
const dependency = dependencies[i]; | ||
const promiseResult = promiseResults[i]; | ||
dependenciesHealth.push({ | ||
name: dependency.name, | ||
data: dependency.data, | ||
healthy, | ||
healthy: promiseResult.status === 'fulfilled' && promiseResult.value, | ||
critical: dependency.critical | ||
@@ -99,2 +93,18 @@ }); | ||
exports.stopCheckingReadiness = stopCheckingReadiness; | ||
const checkDependencyHealth = async (dependency) => { | ||
let healthy = false; | ||
try { | ||
const healthyFunc = dependency.isHealthy ? dependency.isHealthy : dependency.isReady; | ||
healthy = await healthyFunc(); | ||
if (healthy) { | ||
informationLogger?.log(`critical dependency '${dependency.name}' is healthy`); | ||
} | ||
informationLogger?.log(`critical dependency '${dependency.name}' is not healthy`); | ||
} | ||
catch (err) { | ||
// @ts-ignore | ||
informationLogger?.log(`An error occurred while checking health for dependency '${dependencyStateItem.name}', error: ${err.message || err}`); | ||
} | ||
return healthy; | ||
}; | ||
const maximumWaitTimeExceeded = () => { | ||
@@ -101,0 +111,0 @@ (0, exports.stopCheckingReadiness)(); |
{ | ||
"name": "express-service-readiness-middleware", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "This module provides express middleware for determining whether routes are exposed based on service critical dependency health.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -17,3 +17,3 @@ | ||
```bash | ||
$ npm install express-service-readiness-middleware@1.0.9 --save | ||
$ npm install express-service-readiness-middleware@1.0.10 --save | ||
``` | ||
@@ -20,0 +20,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
20972
245