2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-04-14 14:14:00 +09:00
|
|
|
import Redis from 'ioredis';
|
2024-04-04 22:25:28 +09:00
|
|
|
import { loadConfig } from '../built/config.js';
|
2024-08-05 01:09:48 +09:00
|
|
|
import { createPostgresDataSource } from '../built/postgres.js';
|
2023-02-24 14:09:17 +09:00
|
|
|
|
|
|
|
const config = loadConfig();
|
|
|
|
|
2024-08-05 01:09:48 +09:00
|
|
|
// 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,
|
2024-10-10 00:49:49 +09:00
|
|
|
config.redisForReactions,
|
2024-08-05 01:09:48 +09:00
|
|
|
])).forEach(connectToRedis);
|