fix: shutdown gracefully
This commit is contained in:
parent
881fd5f5d8
commit
d6c367f283
2 changed files with 4 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
|||
* @callback BeforeShutdownListener
|
||||
* @param {string} [signalOrEvent] The exit signal or event name received on the process.
|
||||
*/
|
||||
type BeforeShutdownListener = (signalOrEvent: string) => Promise<void>;
|
||||
|
||||
/**
|
||||
* System signals the app will listen to initiate shutdown.
|
||||
|
@ -24,7 +25,7 @@ const SHUTDOWN_TIMEOUT = 15000;
|
|||
* down the process.
|
||||
* @type {BeforeShutdownListener[]}
|
||||
*/
|
||||
const shutdownListeners: ((signalOrEvent: string) => void)[] = [];
|
||||
const shutdownListeners: BeforeShutdownListener[] = [];
|
||||
|
||||
/**
|
||||
* Listen for signals and execute given `fn` function once.
|
||||
|
@ -89,7 +90,7 @@ async function shutdownHandler(signalOrEvent: string) {
|
|||
* @param {BeforeShutdownListener} listener The shutdown listener to register.
|
||||
* @returns {BeforeShutdownListener} Echoes back the supplied `listener`.
|
||||
*/
|
||||
export function beforeShutdown(listener: () => void) {
|
||||
export function beforeShutdown(listener: BeforeShutdownListener): BeforeShutdownListener {
|
||||
shutdownListeners.push(listener);
|
||||
return listener;
|
||||
}
|
||||
|
|
|
@ -6,4 +6,4 @@ export const activeUsersChart = new ActiveUsersChart();
|
|||
// 20分おきにメモリ情報をDBに書き込み
|
||||
setInterval(() => activeUsersChart.save(), 1000 * 60 * 20);
|
||||
|
||||
beforeShutdown(async () => await new Promise(() => activeUsersChart.save()));
|
||||
beforeShutdown(() => activeUsersChart.save());
|
||||
|
|
Loading…
Reference in a new issue