mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-25 00:49:17 +09:00
f30d19051f
* fix race conditions in check_connect.js (cherry picked from commit 524ddb96770690455b82522104a543c5b0b1f3b3) * fix * Update Changelog --------- Co-authored-by: Hazelnoot <acomputerdog@gmail.com>
57 lines
1.2 KiB
JavaScript
57 lines
1.2 KiB
JavaScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import Redis from 'ioredis';
|
|
import { loadConfig } from '../built/config.js';
|
|
import { createPostgresDataSource } from '../built/postgres.js';
|
|
|
|
const config = loadConfig();
|
|
|
|
async function connectToPostgres() {
|
|
const source = createPostgresDataSource(config);
|
|
await source.initialize();
|
|
await source.destroy();
|
|
}
|
|
|
|
async function connectToRedis(redisOptions) {
|
|
return await new Promise(async (resolve, reject) => {
|
|
const redis = new Redis({
|
|
...redisOptions,
|
|
lazyConnect: true,
|
|
reconnectOnError: false,
|
|
showFriendlyErrorStack: true,
|
|
});
|
|
redis.on('error', e => reject(e));
|
|
|
|
try {
|
|
await redis.connect();
|
|
resolve();
|
|
|
|
} catch (e) {
|
|
reject(e);
|
|
|
|
} finally {
|
|
redis.disconnect(false);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 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.
|
|
const promises = Array
|
|
.from(new Set([
|
|
config.redis,
|
|
config.redisForPubsub,
|
|
config.redisForJobQueue,
|
|
config.redisForTimelines,
|
|
config.redisForReactions,
|
|
]))
|
|
.map(connectToRedis)
|
|
.concat([
|
|
connectToPostgres()
|
|
]);
|
|
|
|
await Promise.allSettled(promises);
|