-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move project into dedicated folder
- Loading branch information
1 parent
4325090
commit 00b32cc
Showing
33 changed files
with
460 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HealthIndicatorFunction } from '../health-indicator'; | ||
import { HealthCheckError } from '@godaddy/terminus'; | ||
import { HealthCheckResult } from './health-check-result.interface'; | ||
|
||
/** | ||
* Takes care of the execution of health indicators | ||
* @internal | ||
*/ | ||
@Injectable() | ||
export class HealthCheckExecutor { | ||
/** | ||
* Executes the given health indicators. | ||
* | ||
* @throws {Error} All errors which are not inherited by the `HealthCheckError`-class | ||
* | ||
* @returns the result of given health indicators | ||
* @param healthIndicators The health indicators which should get executed | ||
*/ | ||
async execute( | ||
healthIndicators: HealthIndicatorFunction[], | ||
): Promise<HealthCheckResult> { | ||
const results: any[] = []; | ||
const errors: any[] = []; | ||
await Promise.all( | ||
healthIndicators | ||
// Register all promises | ||
.map(healthIndicator => healthIndicator()) | ||
.map((p: Promise<any>) => | ||
p.catch((error: any) => { | ||
// Is not an expected error. Throw further! | ||
if (!error.causes) throw error; | ||
// Is a expected health check error | ||
errors.push((error as HealthCheckError).causes); | ||
}), | ||
) | ||
.map((p: Promise<any>) => | ||
p.then((result: any) => result && results.push(result)), | ||
), | ||
); | ||
|
||
const info = (results || []) | ||
.concat(errors || []) | ||
.reduce( | ||
(previous: Object, current: Object) => Object.assign(previous, current), | ||
{}, | ||
); | ||
|
||
if (errors.length) { | ||
throw new HealthCheckError('Healthcheck failed', info); | ||
} else { | ||
return info; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* The result of a health check | ||
*/ | ||
export interface HealthCheckResult { | ||
results: any[]; | ||
errors: any[]; | ||
} |
File renamed without changes.
12 changes: 6 additions & 6 deletions
12
lib/health.service.ts → lib/health-check/health-check.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './health-check.service'; | ||
export * from './health-check.decorator'; | ||
export * from './health-check-result.interface'; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
lib/health-indicators/dns/dns.health.ts → lib/health-indicator/dns/dns.health.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dns.health'; |
27 changes: 26 additions & 1 deletion
27
lib/health-indicators/health-indicator.ts → lib/health-indicator/health-indicator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...health-indicators/memory/memory.health.ts → lib/health-indicator/memory/memory.health.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './interfaces'; | ||
export * from './terminus.module'; | ||
export * from './health-indicators'; | ||
export { TerminusModule } from './terminus.module'; | ||
export * from './health-indicator'; | ||
export * from './errors'; | ||
export { HealthCheck, HealthCheckService } from './health-check'; | ||
export * from './terminus-module-options.interface'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.