@piggly/fastify-chassis
Version:
An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.
43 lines • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanupDependencies = void 0;
const tslib_1 = require("tslib");
const ddd_toolkit_1 = require("@piggly/ddd-toolkit");
const event_bus_1 = tslib_1.__importDefault(require("@piggly/event-bus"));
const debug_1 = tslib_1.__importDefault(require("debug"));
/**
* Cleanup dependencies.
* It will run the CleanUpService to clean all registered dependencies.
*
* HTTP Server will be automatically cleaned up if it is registered in the CleanUpService.
*
* It will wait for:
* - EventBus cleanup;
* - LoggerService flush and cleanup.
*
* You may not need to cleanup classes above when using this.
*
* @deprecated Use GracefulShutdownService instead. It will be removed in the next major version.
* @returns {Promise<number>}
* @since 7.3.0
* @author Caique Araujo <caique@piggly.com.br>
*/
const cleanupDependencies = async () => {
try {
await event_bus_1.default.instance.cleanup();
ddd_toolkit_1.LoggerService.softResolve().flush();
await ddd_toolkit_1.LoggerService.softResolve().cleanup();
const service = ddd_toolkit_1.ServiceProvider.get('CleanUpService');
if (service) {
const response = await service.softClean();
return response.success ? 0 : 1;
}
return 0;
}
catch (error) {
(0, debug_1.default)('app:cleanup:error')(error);
return 1;
}
};
exports.cleanupDependencies = cleanupDependencies;
//# sourceMappingURL=cleanupDependencies.js.map