diff --git a/.env.example b/.env.example index 29523df..1173ef4 100755 --- a/.env.example +++ b/.env.example @@ -8,6 +8,7 @@ DOMAIN_API=localhost:5000 DOMAIN_WEBSITE=localhost:3000 SUPERTOKENS_CORE_URI=http://localhost:3567 REDIS_URL=redis://localhost:6379 +BULLMQ_REDIS_URL=redis://localhost:6379 SERVER_PORT=5000 RABBITMQ_URI=amqp://rabbitmq:rabbitmq@localhost:5672 STEAM_API_KEY= diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 023155e..1a87fe0 100755 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -92,11 +92,11 @@ services: timeout: 20s retries: 10 - + # Redis server for caching redis: image: redis:latest hostname: server-redis - command: ["redis-server", "--appendonly", "no", "--maxmemory", "4096mb", "--maxmemory-policy", "allkeys-lru"] + command: ["redis-server", "--appendonly", "yes", "--maxmemory", "2048mb", "--maxmemory-policy", "allkeys-lru"] environment: ALLOW_EMPTY_PASSWORD: 'yes' @@ -114,6 +114,24 @@ services: networks: - game_node_app + # Redis server exclusive to BullMQ + redis_bullmq: + image: redis:latest + hostname: server-redis-bullmq + command: ["redis-server", "--appendonly", "yes", "--maxmemory", "6144mb", "--maxmemory-policy", "noeviction"] + environment: + ALLOW_EMPTY_PASSWORD: 'yes' + restart: always + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + volumes: + - redis_bullmq:/var/lib/redis + + networks: + - game_node_app + + + server: image: lamarcke/game-node-server:latest hostname: server @@ -122,6 +140,7 @@ services: # the docker resources are accessible. environment: REDIS_URL: redis://server-redis:6379 + BULLMQ_REDIS_URL: redis://server-redis-bullmq:6379 SUPERTOKENS_CORE_URI: http://@supertokens:3567 SERVER_PORT: 5000 DOMAIN_API: https://server.gamenode.app @@ -174,7 +193,6 @@ services: image: lamarcke/game-node-server:latest hostname: server-migration environment: - REDIS_URL: redis://server-redis:6379 DB_HOST: server-db DB_DATABASE: gamenode DB_PASS: ${DB_PASS} @@ -183,6 +201,9 @@ services: restart: always + # The server process is not meant to actually be started here. + # This could be done better, but we need to manually check every migration + # before running. command: "sleep infinity" deploy: @@ -201,6 +222,7 @@ networks: volumes: redis: + redis_bullmq: db: gamenode: supertokens-db: diff --git a/src/app.module.ts b/src/app.module.ts index 1f73b36..a684d2a 100755 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -35,12 +35,15 @@ import { PlaytimeWatchModule } from "./playtime/watch/playtime-watch.module"; /** * Should only be called after 'ConfigModule' is loaded (e.g. in useFactory) */ -function getRedisConfig() { +function getRedisConfig(target: "cache" | "bullmq" = "cache") { /** * While the "redis" property below accepts a string, and it works fine on local, * it fails on Docker, so use host and port instead. */ - const redisUrl = process.env.REDIS_URL; + let redisUrl = process.env.REDIS_URL; + if (target === "bullmq") { + redisUrl = process.env.BULLMQ_REDIS_URL; + } const redisHost = new URL(redisUrl!).hostname; const redisPort = new URL(redisUrl!).port; @@ -101,18 +104,19 @@ function getRedisConfig() { }; }, }), - CacheModule.registerAsync({ isGlobal: true, + inject: [ConfigService], useFactory: async () => ({ store: await redisStore({ - url: process.env.REDIS_URL, + url: getRedisConfig().url, }), }), }), BullModule.forRootAsync({ + inject: [ConfigService], useFactory: async () => { - const { port, host } = getRedisConfig(); + const { port, host } = getRedisConfig("bullmq"); return { connection: {