|
1 | 1 | /* eslint-disable import/first */ |
2 | 2 | import * as Events from 'events' |
3 | 3 | Events.EventEmitter.defaultMaxListeners = 30 |
| 4 | + |
4 | 5 | import { Sentry } from './monitoring/instrument' |
5 | 6 | import express from 'express' |
6 | 7 | import asyncHandler from 'express-async-handler' |
@@ -865,20 +866,26 @@ async function bootstrap (): Promise<void> { |
865 | 866 | }, restartDelay) |
866 | 867 | } |
867 | 868 |
|
868 | | - if (dbConnected) { |
869 | | - // Periodically check database connection and attempt to reconnect if needed |
870 | | - setInterval(() => { |
871 | | - void (async () => { |
872 | | - try { |
873 | | - if (!AppDataSource.isInitialized) { |
874 | | - logger.warn('Database connection lost, attempting to reconnect...') |
875 | | - await connectToDatabase(3) // Use fewer retries for periodic checks |
876 | | - } |
877 | | - } catch (error) { |
878 | | - logger.error(`Database monitoring error: ${(error as Error).message}`) |
879 | | - } |
880 | | - })() |
881 | | - }, 5 * 60 * 1000) // Check every minute |
| 869 | + try { |
| 870 | + payments.bootstrap() |
| 871 | + } catch (error) { |
| 872 | + logger.error(`Payments bootstrap error: ${error}`) |
| 873 | + // Continue despite payment initialization errors |
| 874 | + } |
| 875 | + |
| 876 | + if (dbConnected && AppDataSource.driver) { |
| 877 | + try { |
| 878 | + // Handle any driver-level errors that bubble up |
| 879 | + const driver = AppDataSource.driver as any |
| 880 | + // Only attach to events if they're available, don't force it |
| 881 | + if (driver.eventEmitter && typeof driver.eventEmitter.on === 'function') { |
| 882 | + driver.eventEmitter.on('error', (error: any) => { |
| 883 | + logger.error(`Database error event: ${error.message}`) |
| 884 | + }) |
| 885 | + } |
| 886 | + } catch (error) { |
| 887 | + logger.warn(`Could not set up database error listener: ${(error as Error).message}`) |
| 888 | + } |
882 | 889 | } |
883 | 890 | } |
884 | 891 |
|
|
0 commit comments