@@ -12,17 +12,15 @@ import {
1212import { ApolloServer } from "apollo-server-fastify" ;
1313import responseCachePlugin from "apollo-server-plugin-response-cache" ;
1414import fastify , { FastifyContext , FastifyReply , FastifyRequest } from "fastify" ;
15- import Redis from "ioredis " ;
15+ import { createCluster } from "redis " ;
1616import { MongoClient } from "mongodb" ;
17- import pEvent from "p-event" ;
1817
1918import appUpdate from "./generic/appUpdate" ;
2019import ffUpdates from "./generic/ffUpdates" ;
2120import zippedPresences from "./generic/zippedPresences" ;
2221import fastifyAppClosePlugin from "./plugins/fastifyAppClosePlugin" ;
2322import sentryPlugin from "./plugins/sentryPlugin" ;
2423import dataSources from "./util/dataSources" ;
25- import zipPresences from "./util/functions/zipPresences" ;
2624import deleteScience from "./v2/deleteScience" ;
2725import versions from "./v2/versions" ;
2826import { resolvers as v3Resolvers } from "./v3/resolvers" ;
@@ -45,25 +43,25 @@ if (process.env.SENTRY_DSN)
4543export const mongodb = new MongoClient ( process . env . MONGO_URL ! , {
4644 appName : "PreMiD-API-Worker"
4745 } ) ,
48- redis = new Redis ( {
49- sentinels : [
46+ redis = createCluster ( {
47+ rootNodes : [
5048 {
51- host : process . env . REDIS_HOST || "localhost" ,
52- port : parseInt ( process . env . REDIS_PORT || "26379" )
49+ url : process . env . REDIS_URL || "redis://localhost:6379"
5350 }
5451 ] ,
55- name : "mymaster"
52+ useReplicas : true
5653 } ) ,
5754 baseRedisCache = new BaseRedisCache ( {
5855 //@ts -ignore
5956 client : redis
6057 } ) ,
61- dSources = dataSources ( ) ,
6258 app = fastify ( {
6359 connectionTimeout : 10_000 ,
6460 keepAliveTimeout : 10_000
6561 } ) ;
6662
63+ export let dSources : ReturnType < typeof dataSources > ;
64+
6765export let v3Server : ApolloServer < FastifyContext > ,
6866 v4Server : ApolloServer < FastifyContext > ;
6967
@@ -72,6 +70,14 @@ export interface Context {
7270}
7371
7472async function run ( ) {
73+ redis . setMaxListeners ( 12 ) ;
74+ redis . on ( "error" , error => {
75+ console . log ( error ) ;
76+ } ) ;
77+ await redis . connect ( ) ;
78+
79+ dSources = dataSources ( ) ;
80+
7581 const apolloGenericSettings = {
7682 dataSources : ( ) => dSources ,
7783 context : ( req : FastifyRequest , res : FastifyReply ) => {
@@ -111,17 +117,7 @@ async function run() {
111117 resolvers : await v4Resolvers
112118 } ) ;
113119
114- await Promise . all ( [
115- mongodb . connect ( ) ,
116- pEvent ( redis , "connect" ) ,
117- v3Server . start ( ) ,
118- v4Server . start ( ) ,
119- zipPresences ( )
120- ] ) ;
121-
122- setInterval ( ( ) => {
123- zipPresences ( ) ;
124- } , 60_000 ) ;
120+ await Promise . all ( [ mongodb . connect ( ) , v3Server . start ( ) , v4Server . start ( ) ] ) ;
125121
126122 app . addHook ( "onError" , ( _ , _1 , error , done ) => {
127123 Sentry . captureException ( error ) ;
0 commit comments