MCPcopy Create free account
hub / github.com/LeChatErrant/API-template / waitApp

Function waitApp

src/utils/waitApp.ts:6–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { config } from '../appConfig';
5
6export default async function waitApp() {
7 /* Prisma */
8 logger.info('Waiting database...');
9 await db
10 .$connect()
11 .then(() => {
12 logger.info('Connected to database !');
13 })
14 .catch((error) => {
15 logger.error(error);
16 logger.error(`Can't connect to database at url ${config.dbUrl}`);
17 throw error;
18 });
19
20 /* Redis */
21 if (redisClient) {
22 logger.info('Waiting redis...');
23 await new Promise<void>((resolve) => {
24 const interval = setInterval(() => {
25 const isConnected = redisClient?.ping();
26 if (isConnected) {
27 clearInterval(interval);
28 resolve();
29 }
30 }, 1000);
31 });
32 logger.info('Connected to redis !');
33 }
34}

Callers 3

mainFunction · 0.85
user.spec.tsFile · 0.85
post.spec.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected