UNPKG

@piggly/fastify-chassis

Version:

An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.

116 lines (115 loc) 3.38 kB
import type { CleanUpService } from '../services/CleanUpService.js'; /** * @file Handle graceful shutdown of the service. * @copyright Piggly Lab 2025 * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ export declare class GracefulShutdownService { /** * The cleanup service to use. * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ protected cleanup?: CleanUpService; /** * Whether the service is shutting down. * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ protected is_shutting_down: boolean; /** * The timeout in milliseconds. * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ protected timeout: number; /** * Constructor. * @param {CleanUpService} cleanup The cleanup service to use. * @param {number} timeout The timeout in milliseconds. Default is 30000. * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ constructor(cleanup?: CleanUpService, timeout?: number); /** * Get the cleanup service. * * @returns {CleanUpService} * @throws {Error} If cleanup service is not provided. * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ get handlers(): CleanUpService; /** * Fetch the cleanup service. * Useful when you want to delay the cleanup to a later time. * * E.g: You want to listen for shutdown signals and it can * happen before the cleanup service is ready. * * If "cleanup" is not provided, it will try to load the cleanup service * from the ServiceProvider. * * @param {CleanUpService} cleanup The cleanup service to use. * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ fetch(cleanup?: CleanUpService): void; /** * Listen for shutdown signals. * * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ listen(): void; /** * Listen for uncaught exceptions and rejections. * * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ listenUncaught(): void; /** * Listen for user signals. * * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ listenUSR(): void; /** * Shutdown the service. * * @returns {Promise<void>} * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ shutdown(): Promise<void>; /** * Clean up the service. * * @returns {Promise<boolean>} * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ protected _clean(): Promise<boolean>; /** * Shutdown the service. * * @param {string} signal The signal that triggered the shutdown. * @returns {Promise<void>} * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ private _shutdown; /** * Resolve the graceful shutdown service. * It will load the CleanUpService from the ServiceProvider. * * @param {number} timeout The timeout in milliseconds. Default is 30000. * @returns {GracefulShutdownService} * @since 7.5.0 * @author Caique Araujo <caique@piggly.com.br> */ static resolve(timeout?: number): GracefulShutdownService; }