mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
Wait for redis to connect before starting server
This commit is contained in:
@@ -4,6 +4,7 @@ import { createServer } from "./app";
|
|||||||
import { Logger } from "./utils/logger";
|
import { Logger } from "./utils/logger";
|
||||||
import { startAllCrons } from "./cronjob";
|
import { startAllCrons } from "./cronjob";
|
||||||
import { getCommit } from "./utils/getCommit";
|
import { getCommit } from "./utils/getCommit";
|
||||||
|
import { connectionPromise } from "./utils/redis";
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
process.on("unhandledRejection", (error: any) => {
|
process.on("unhandledRejection", (error: any) => {
|
||||||
@@ -14,6 +15,7 @@ async function init() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await initDb();
|
await initDb();
|
||||||
|
await connectionPromise;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(`Init Db: ${e}`);
|
Logger.error(`Init Db: ${e}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
@@ -42,12 +42,14 @@ const writeResponseTime: number[] = [];
|
|||||||
let lastResponseTimeLimit = 0;
|
let lastResponseTimeLimit = 0;
|
||||||
const maxStoredTimes = 200;
|
const maxStoredTimes = 200;
|
||||||
|
|
||||||
|
export let connectionPromise = Promise.resolve();
|
||||||
|
|
||||||
if (config.redis?.enabled) {
|
if (config.redis?.enabled) {
|
||||||
Logger.info("Connected to redis");
|
Logger.info("Connected to redis");
|
||||||
const client = createClient(config.redis);
|
const client = createClient(config.redis);
|
||||||
const readClient = config.redisRead?.enabled ? createClient(config.redisRead) : null;
|
const readClient = config.redisRead?.enabled ? createClient(config.redisRead) : null;
|
||||||
void client.connect(); // void as we don't care about the promise
|
connectionPromise = client.connect();
|
||||||
void readClient?.connect();
|
void readClient?.connect(); // void as we don't care about the promise
|
||||||
exportClient = client as RedisSB;
|
exportClient = client as RedisSB;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user