Skip to content

Commit

Permalink
fix: closed redis connection
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed May 3, 2024
1 parent ad539ed commit 3679cda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/src/graphql/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ export const startServer = async (
): Promise<Server> => {
logger.debug('Starting server');

if (process.env.REDIS_TLS_URL) {
await initRedis();
}

const apolloIndex = createApolloIndexServer();
const apolloDrive = createApolloDriveServer();

await apolloIndex.start();
await apolloDrive.start();

if (process.env.REDIS_TLS_URL) {
await initRedis()
}


router.use(
'/drives',
Expand Down
2 changes: 2 additions & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createApp } from './app';
import { startServer } from './graphql/server';
import { getChildLogger } from './logger';
import { closeRedis } from './redis';

const logger = getChildLogger({ msgPrefix: 'SERVER' });

Expand All @@ -18,6 +19,7 @@ startServer(app, router)
})
.catch((err) => {
logger.warn('Shutting down...');
closeRedis();
if (err instanceof Error) {
logger.error(err);
} else {
Expand Down
15 changes: 15 additions & 0 deletions api/src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ export const initRedis = async () => {

return redisClient;
}



const timer = setInterval(async () => {
try {
redisClient && await redisClient.ping();
} catch (err) {
console.error('Ping Interval Error', err);
}
}, 1000 * 60 * 4);

export const closeRedis = () => {
clearInterval(timer);
redisClient && redisClient.disconnect();
}

0 comments on commit 3679cda

Please sign in to comment.