summaryrefslogtreecommitdiff
path: root/packages/backend/scripts
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-10-28 21:06:54 +0900
committerGitHub <noreply@github.com>2024-10-28 21:06:54 +0900
commitf30d19051fb67f800185da283672ae7f9e8c535e (patch)
tree38c210ae24044e44ff906db1af1ea7aa0ca14725 /packages/backend/scripts
parentfix(backend): Accept arrays in ActivityPub `icon` and `image` properties (#14... (diff)
downloadmisskey-f30d19051fb67f800185da283672ae7f9e8c535e.tar.gz
misskey-f30d19051fb67f800185da283672ae7f9e8c535e.tar.bz2
misskey-f30d19051fb67f800185da283672ae7f9e8c535e.zip
enhance(backend): check_connect.js で全RedisとDBへの接続を確認するように (#14853)
* fix race conditions in check_connect.js (cherry picked from commit 524ddb96770690455b82522104a543c5b0b1f3b3) * fix * Update Changelog --------- Co-authored-by: Hazelnoot <acomputerdog@gmail.com>
Diffstat (limited to 'packages/backend/scripts')
-rw-r--r--packages/backend/scripts/check_connect.js51
1 files changed, 46 insertions, 5 deletions
diff --git a/packages/backend/scripts/check_connect.js b/packages/backend/scripts/check_connect.js
index ba25fd416c..bb149444b5 100644
--- a/packages/backend/scripts/check_connect.js
+++ b/packages/backend/scripts/check_connect.js
@@ -5,11 +5,52 @@
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;
-});
+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);