diff --git a/typings/index.d.ts b/typings/index.d.ts index 72521e8..66424a5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3,7 +3,7 @@ declare module "@godaddy/terminus" { isShuttingDown: boolean; } - export type HealthCheck = ({ state }: { state: TerminusState }) => Promise; + export type HealthCheck = ({ state }: { state: TerminusState }) => Promise | any; export class HealthCheckError extends Error { constructor(message: string, causes: any); @@ -28,10 +28,10 @@ declare module "@godaddy/terminus" { statusError?: number, statusErrorResponse?: Record, useExit0?: boolean, - onSignal?: () => Promise; - onSendFailureDuringShutdown?: () => Promise; - onShutdown?: () => Promise; - beforeShutdown?: () => Promise; + onSignal?: () => Promise | void; + onSendFailureDuringShutdown?: () => Promise | void; + onShutdown?: () => Promise | void; + beforeShutdown?: () => Promise | void; logger?: (msg: string, err: Error) => void; headers?:{ [key: string]: string }; diff --git a/typings/index.test.ts b/typings/index.test.ts index a151433..230e16e 100644 --- a/typings/index.test.ts +++ b/typings/index.test.ts @@ -8,9 +8,13 @@ async function onSignal() { ]); } -async function onShutdown() { +async function onShutdownAsync() { + console.log('cleanup finished, server is shutting down'); + return true; +} + +const onShutdown: TerminusOptions["onShutdown"] = () => { console.log('cleanup finished, server is shutting down'); - return Promise.resolve(); } const server = http.createServer((request, response) => { @@ -23,14 +27,25 @@ const healthcheck: HealthCheck = () => { throw error; } +const healthcheckAsync: HealthCheck = async () => { + const result = await Promise.resolve([{ status: 'up' }]); + return result; +} + +const healthcheckSync: HealthCheck = () => { + return [{ status: 'up' }]; +} + const options: TerminusOptions = { healthChecks: { "/healthcheck": healthcheck, + "/healthcheck-sync": healthcheckSync, + "/healthcheck-async": healthcheckAsync, verbatim: true }, timeout: 1000, onSignal, - onShutdown, + onShutdown: onShutdownAsync, logger: console.log };