-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.handlers.ts
More file actions
51 lines (47 loc) · 1.43 KB
/
Copy pathapp.handlers.ts
File metadata and controls
51 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { dbConfig, redisConfig } from '@root/app.config';
import db from '@services/database';
import logger from '@services/logger';
import redis from '@services/redis';
/**
* Wait for all services to be up
*/
export async function waitServices() {
/* Prisma */
logger.info('Connecting to database...');
await db
.$connect()
.then(() => {
logger.info('Connected to database !');
})
.catch((error) => {
logger.error(`Can't connect to database at url ${dbConfig.url}`);
logger.debug('Try running `npm run dev:db` to quickly launch a PostgreSQL instance !');
throw error;
});
/* Redis */
logger.info('Connecting to redis...');
try {
await redis.connect();
} catch (error) {
logger.error(`Can't connect to redis at url redis://:${redisConfig.password}@${redisConfig.host}:${redisConfig.port}`);
logger.debug('Try running `npm run dev:redis` to quickly launch a Redis instance !');
throw error;
}
logger.info('Connected to redis !');
}
/**
* Gracefully close connection with services to avoid zombies processes
*/
export async function gracefullyCloseConnections() {
/* Prisma */
logger.info('Disconnecting from database...');
await db
.$disconnect()
.then(() => {
logger.info('Disconnected from database !');
});
/* Redis */
logger.info('Disconnecting from redis...');
await redis.disconnect();
logger.info('Disconnected from redis !');
}