Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module "@godaddy/terminus" {
isShuttingDown: boolean;
}

export type HealthCheck = ({ state }: { state: TerminusState }) => Promise<any>;
export type HealthCheck = ({ state }: { state: TerminusState }) => Promise<any> | any;

export class HealthCheckError extends Error {
constructor(message: string, causes: any);
Expand All @@ -28,10 +28,10 @@ declare module "@godaddy/terminus" {
statusError?: number,
statusErrorResponse?: Record<string, unknown>,
useExit0?: boolean,
onSignal?: () => Promise<any>;
onSendFailureDuringShutdown?: () => Promise<any>;
onShutdown?: () => Promise<any>;
beforeShutdown?: () => Promise<any>;
onSignal?: () => Promise<any> | void;
onSendFailureDuringShutdown?: () => Promise<any> | void;
onShutdown?: () => Promise<any> | void;
beforeShutdown?: () => Promise<any> | void;
logger?: (msg: string, err: Error) => void;
headers?:{ [key: string]: string };

Expand Down
21 changes: 18 additions & 3 deletions typings/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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
};

Expand Down