diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-08-06 17:51:51 +0100 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-08-06 17:51:51 +0100 |
| commit | 94dceb9e15474f85d94b7ea89a5e2197d4f9b6fc (patch) | |
| tree | 6bb6da6dea6e802a5c5106a90564e11b01a31ddd /packages/backend/scripts | |
| parent | appease the linter (diff) | |
| parent | merge: Remove infinite caches to prevent memory leak (!587) (diff) | |
| download | sharkey-94dceb9e15474f85d94b7ea89a5e2197d4f9b6fc.tar.gz sharkey-94dceb9e15474f85d94b7ea89a5e2197d4f9b6fc.tar.bz2 sharkey-94dceb9e15474f85d94b7ea89a5e2197d4f9b6fc.zip | |
Merge branch 'develop' into feature/misskey-2024.07
Diffstat (limited to 'packages/backend/scripts')
| -rw-r--r-- | packages/backend/scripts/check_connect.js | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/packages/backend/scripts/check_connect.js b/packages/backend/scripts/check_connect.js index ba25fd416c..d4bf4baf43 100644 --- a/packages/backend/scripts/check_connect.js +++ b/packages/backend/scripts/check_connect.js @@ -5,11 +5,33 @@ import Redis from 'ioredis'; import { loadConfig } from '../built/config.js'; +import { createPostgresDataSource } from '../built/postgres.js'; const config = loadConfig(); -const redis = new Redis(config.redis); -redis.on('connect', () => redis.disconnect()); -redis.on('error', (e) => { - throw e; -}); +// createPostgresDataSource handels primaries and replicas automatically. +// usually, it only opens connections first use, so we force it using +// .initialize() +createPostgresDataSource(config) + .initialize() + .then(c => { c.destroy() }) + .catch(e => { throw e }); + + +// Connect to all redis servers +function connectToRedis(redisOptions) { + const redis = new Redis(redisOptions); + redis.on('connect', () => redis.disconnect()); + redis.on('error', (e) => { + throw e; + }); +} + +// If not all of these are defined, the default one gets reused. +// so we use a Set to only try connecting once to each **uniq** redis. +(new Set([ + config.redis, + config.redisForPubsub, + config.redisForJobQueue, + config.redisForTimelines, +])).forEach(connectToRedis); |