@@ -42,13 +42,14 @@ const prisma = new PrismaClient({
4242const redis = new Redis ( env . REDIS_URL , {
4343 maxRetriesPerRequest : null
4444} ) ;
45- redis . ping ( ) . then ( ( ) => {
45+
46+ try {
47+ await redis . ping ( ) ;
4648 logger . info ( 'Connected to redis' ) ;
47- } ) . catch ( ( err : unknown ) => {
48- logger . error ( 'Failed to connect to redis' ) ;
49- logger . error ( err ) ;
49+ } catch ( err : unknown ) {
50+ logger . error ( 'Failed to connect to redis. Error:' , err ) ;
5051 process . exit ( 1 ) ;
51- } ) ;
52+ }
5253
5354const promClient = new PromClient ( ) ;
5455
@@ -85,8 +86,6 @@ const api = new Api(
8586
8687logger . info ( 'Worker started.' ) ;
8788
88-
89-
9089const listenToShutdownSignals = ( ) => {
9190 const signals = SHUTDOWN_SIGNALS ;
9291
@@ -115,29 +114,34 @@ const listenToShutdownSignals = () => {
115114
116115
117116 logger . info ( 'All workers shut down gracefully' ) ;
118-
119117 signals . forEach ( sig => process . removeListener ( sig , cleanup ) ) ;
120- process . kill ( process . pid , signal ) ;
121118 } catch ( error ) {
122119 Sentry . captureException ( error ) ;
123120 logger . error ( 'Error shutting down worker:' , error ) ;
124- process . exit ( 1 ) ;
125121 }
126122 }
127123
128124 signals . forEach ( signal => {
129- process . on ( signal , cleanup ) ;
125+ process . on ( signal , ( err ) => {
126+ cleanup ( err ) . finally ( ( ) => {
127+ process . kill ( process . pid , signal ) ;
128+ } ) ;
129+ } ) ;
130130 } ) ;
131131
132132 // Register handlers for uncaught exceptions and unhandled rejections
133133 process . on ( 'uncaughtException' , ( err ) => {
134134 logger . error ( `Uncaught exception: ${ err . message } ` ) ;
135- cleanup ( 'uncaughtException' ) . finally ( ( ) => process . exit ( 1 ) ) ;
135+ cleanup ( 'uncaughtException' ) . finally ( ( ) => {
136+ process . exit ( 1 ) ;
137+ } ) ;
136138 } ) ;
137139
138140 process . on ( 'unhandledRejection' , ( reason , promise ) => {
139141 logger . error ( `Unhandled rejection at: ${ promise } , reason: ${ reason } ` ) ;
140- cleanup ( 'unhandledRejection' ) . finally ( ( ) => process . exit ( 1 ) ) ;
142+ cleanup ( 'unhandledRejection' ) . finally ( ( ) => {
143+ process . exit ( 1 ) ;
144+ } ) ;
141145 } ) ;
142146
143147
0 commit comments