Browse Source

Merge pull request #24749 from overleaf/bg-history-redis-buffer

add history redis to history-v1

GitOrigin-RevId: 70dc1aee809ad17902c93c020f3804c0f1429238
Brian Gough 1 year ago
parent
commit
4ba0e97b95

+ 10 - 0
services/history-v1/config/custom-environment-variables.json

@@ -89,6 +89,16 @@
       "host": "QUEUES_REDIS_HOST",
       "password": "QUEUES_REDIS_PASSWORD",
       "port": "QUEUES_REDIS_PORT"
+    },
+    "history": {
+      "host": "HISTORY_REDIS_HOST",
+      "password": "HISTORY_REDIS_PASSWORD",
+      "port": "HISTORY_REDIS_PORT"
+    },
+    "lock": {
+      "host": "REDIS_HOST",
+      "password": "REDIS_PASSWORD",
+      "port": "REDIS_PORT"
     }
   }
 }

+ 19 - 2
services/history-v1/storage/scripts/redis.mjs

@@ -1,11 +1,28 @@
 import redis from '@overleaf/redis-wrapper'
 import config from 'config'
 
-const redisOptions = config.get('redis.queue')
+// Get allowed Redis dbs from config
+const redisConfig = config.get('redis')
+const allowedDbs = Object.keys(redisConfig)
 
+// Get the Redis db from command line argument or use the first available db as default
+const db = process.argv[2]
+
+// Validate redis db
+if (!allowedDbs.includes(db)) {
+  if (db) {
+    console.error('Invalid redis db:', db)
+  }
+  console.error(`Usage: node redis.mjs [${allowedDbs.join('|')}]`)
+  process.exit(1)
+}
+
+// Get redis options based on command line argument
+const redisOptions = config.get(`redis.${db}`)
+console.log('Using redis db:', db)
 console.log('REDIS CONFIG', {
   ...redisOptions,
-  password: '*'.repeat(redisOptions.password.length),
+  password: '*'.repeat(redisOptions.password?.length),
 })
 const rclient = redis.createClient(redisOptions)