1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

feat: Added shutdown hook option (#6585)

An entrypoint for enterprise to register a hook which will be called
before the database and scheduler services are torn down. That way
enterprise can also perform graceful shutdown.
This commit is contained in:
Christopher Kolstad 2024-03-15 14:05:35 +01:00 committed by GitHub
parent fca6146b3a
commit d5bc3585aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -12,13 +12,13 @@ import { createDb } from './db/db-pool';
import sessionDb from './middleware/session-db';
// Types
import {
CustomAuthHandler,
IAuthType,
IUnleash,
IUnleashConfig,
IUnleashOptions,
IUnleashServices,
RoleName,
CustomAuthHandler,
SYSTEM_USER,
} from './types';
@ -59,6 +59,13 @@ async function createApp(
const stopServer = promisify(server.stop);
await stopServer();
}
if (typeof config.shutdownHook === 'function') {
try {
await config.shutdownHook();
} catch (e) {
logger.error('Failure when executing shutdown hook', e);
}
}
services.schedulerService.stop();
services.addonService.destroy();
await db.destroy();

View File

@ -2,7 +2,7 @@ import { Express } from 'express';
import EventEmitter from 'events';
import { LogLevel, LogProvider } from '../logger';
import { ILegacyApiTokenCreate } from './models/api-token';
import { IFlagResolver, IExperimentalOptions, IFlags } from './experimental';
import { IExperimentalOptions, IFlagResolver, IFlags } from './experimental';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { IUnleashServices } from './services';
import { ResourceLimitsSchema } from '../openapi/spec/resource-limits-schema';
@ -231,6 +231,7 @@ export interface IUnleashConfig {
enableOAS: boolean;
preHook?: Function;
preRouterHook?: Function;
shutdownHook?: Function;
enterpriseVersion?: string;
eventBus: EventEmitter;
environmentEnableOverrides?: string[];