WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Class StartupManager

    Main startup orchestration class for WayrApp sovereign nodes.

    Manages the complete initialization lifecycle of a community-owned educational platform node, including database optimization, cache warming, health monitoring, and graceful shutdown. This class ensures optimal performance from startup and maintains system health through automated maintenance tasks.

    // Basic usage with singleton instance
    import { startupManager } from '@/shared/utils/startup';

    // Initialize the application
    await startupManager.initialize();

    // Check system health
    const isHealthy = await startupManager.healthCheck();
    if (!isHealthy) {
    console.error('System health check failed');
    process.exit(1);
    }

    // Graceful shutdown
    await startupManager.shutdown();
    // Custom instance usage
    const customStartup = new StartupManager();
    await customStartup.initialize();
    Index

    Constructors

    • Creates a new StartupManager instance.

      Initializes the database optimizer with the Prisma client connection. The constructor sets up the foundation for all startup operations but does not perform any initialization tasks - call initialize() for that.

      Returns StartupManager

    Methods

    • Initialize all performance optimizations and startup procedures.

      Orchestrates the complete startup sequence including database optimization, cache warming, and maintenance task setup. This method should be called during application startup to ensure optimal performance from the beginning.

      Returns Promise<void>

      Promise that resolves when initialization is complete

      Throws if critical initialization steps fail

      // Initialize during application startup
      try {
      await startupManager.initialize();
      console.log('Application ready to serve requests');
      } catch (error) {
      console.error('Startup failed:', error);
      process.exit(1);
      }
    • Graceful shutdown cleanup for application termination.

      Performs orderly cleanup of resources including cache clearing and database disconnection. This method should be called during application shutdown to ensure proper resource cleanup and prevent data corruption.

      Returns Promise<void>

      Promise that resolves when shutdown is complete

      // Handle graceful shutdown on SIGTERM
      process.on('SIGTERM', async () => {
      console.log('Received SIGTERM, shutting down gracefully...');
      await startupManager.shutdown();
      process.exit(0);
      });
    • Health check for startup readiness and system status verification.

      Performs comprehensive health checks including database connectivity and cache functionality tests. This method is essential for determining if the application is ready to serve requests and for monitoring system health.

      Returns Promise<boolean>

      Promise that resolves to true if all health checks pass, false otherwise

      // Verify system health before starting server
      const isHealthy = await startupManager.healthCheck();
      if (!isHealthy) {
      logger.error('Health check failed, aborting startup');
      process.exit(1);
      }
      // Periodic health monitoring
      setInterval(async () => {
      const healthy = await startupManager.healthCheck();
      if (!healthy) {
      logger.warn('Health check failed during runtime');
      }
      }, 60000); // Check every minute