@@ -12,17 +12,15 @@ import {
12
12
import { ApolloServer } from "apollo-server-fastify" ;
13
13
import responseCachePlugin from "apollo-server-plugin-response-cache" ;
14
14
import fastify , { FastifyContext , FastifyReply , FastifyRequest } from "fastify" ;
15
- import Redis from "ioredis " ;
15
+ import { createCluster } from "redis " ;
16
16
import { MongoClient } from "mongodb" ;
17
- import pEvent from "p-event" ;
18
17
19
18
import appUpdate from "./generic/appUpdate" ;
20
19
import ffUpdates from "./generic/ffUpdates" ;
21
20
import zippedPresences from "./generic/zippedPresences" ;
22
21
import fastifyAppClosePlugin from "./plugins/fastifyAppClosePlugin" ;
23
22
import sentryPlugin from "./plugins/sentryPlugin" ;
24
23
import dataSources from "./util/dataSources" ;
25
- import zipPresences from "./util/functions/zipPresences" ;
26
24
import deleteScience from "./v2/deleteScience" ;
27
25
import versions from "./v2/versions" ;
28
26
import { resolvers as v3Resolvers } from "./v3/resolvers" ;
@@ -45,25 +43,25 @@ if (process.env.SENTRY_DSN)
45
43
export const mongodb = new MongoClient ( process . env . MONGO_URL ! , {
46
44
appName : "PreMiD-API-Worker"
47
45
} ) ,
48
- redis = new Redis ( {
49
- sentinels : [
46
+ redis = createCluster ( {
47
+ rootNodes : [
50
48
{
51
- host : process . env . REDIS_HOST || "localhost" ,
52
- port : parseInt ( process . env . REDIS_PORT || "26379" )
49
+ url : process . env . REDIS_URL || "redis://localhost:6379"
53
50
}
54
51
] ,
55
- name : "mymaster"
52
+ useReplicas : true
56
53
} ) ,
57
54
baseRedisCache = new BaseRedisCache ( {
58
55
//@ts -ignore
59
56
client : redis
60
57
} ) ,
61
- dSources = dataSources ( ) ,
62
58
app = fastify ( {
63
59
connectionTimeout : 10_000 ,
64
60
keepAliveTimeout : 10_000
65
61
} ) ;
66
62
63
+ export let dSources : ReturnType < typeof dataSources > ;
64
+
67
65
export let v3Server : ApolloServer < FastifyContext > ,
68
66
v4Server : ApolloServer < FastifyContext > ;
69
67
@@ -72,6 +70,14 @@ export interface Context {
72
70
}
73
71
74
72
async 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
+
75
81
const apolloGenericSettings = {
76
82
dataSources : ( ) => dSources ,
77
83
context : ( req : FastifyRequest , res : FastifyReply ) => {
@@ -111,17 +117,7 @@ async function run() {
111
117
resolvers : await v4Resolvers
112
118
} ) ;
113
119
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 ( ) ] ) ;
125
121
126
122
app . addHook ( "onError" , ( _ , _1 , error , done ) => {
127
123
Sentry . captureException ( error ) ;
0 commit comments