2024-06-27 02:44:08 +02:00
|
|
|
import { configureLoggers } from "@/loggers";
|
|
|
|
|
import { getLogger } from "@logtape/logtape";
|
2024-11-01 20:57:16 +01:00
|
|
|
import { Note } from "@versia/kit/db";
|
2024-11-25 21:54:31 +01:00
|
|
|
import chalk from "chalk";
|
2024-11-24 22:01:01 +01:00
|
|
|
import IORedis from "ioredis";
|
2025-02-15 02:47:29 +01:00
|
|
|
import { config } from "~/config.ts";
|
2024-06-27 02:44:08 +02:00
|
|
|
import { setupDatabase } from "~/drizzle/db";
|
2024-11-25 21:54:31 +01:00
|
|
|
import { searchManager } from "../../classes/search/search-manager.ts";
|
2024-06-27 02:44:08 +02:00
|
|
|
|
|
|
|
|
const timeAtStart = performance.now();
|
|
|
|
|
|
|
|
|
|
await configureLoggers();
|
|
|
|
|
|
|
|
|
|
const serverLogger = getLogger("server");
|
|
|
|
|
|
2024-11-10 13:08:26 +01:00
|
|
|
console.info(`
|
|
|
|
|
██╗ ██╗███████╗██████╗ ███████╗██╗ █████╗
|
|
|
|
|
██║ ██║██╔════╝██╔══██╗██╔════╝██║██╔══██╗
|
|
|
|
|
██║ ██║█████╗ ██████╔╝███████╗██║███████║
|
|
|
|
|
╚██╗ ██╔╝██╔══╝ ██╔══██╗╚════██║██║██╔══██║
|
|
|
|
|
╚████╔╝ ███████╗██║ ██║███████║██║██║ ██║
|
|
|
|
|
╚═══╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝
|
2024-11-25 21:54:31 +01:00
|
|
|
${chalk.redBright.bold("** WORKER MODE **")}
|
2024-11-10 13:08:26 +01:00
|
|
|
`);
|
|
|
|
|
|
2024-11-25 21:54:31 +01:00
|
|
|
serverLogger.info`Starting Versia Server Worker...`;
|
2024-06-27 02:44:08 +02:00
|
|
|
|
|
|
|
|
await setupDatabase();
|
|
|
|
|
|
2025-02-15 02:47:29 +01:00
|
|
|
if (config.search.enabled) {
|
2024-06-29 11:40:44 +02:00
|
|
|
await searchManager.connect();
|
2024-06-27 02:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if database is reachable
|
|
|
|
|
const postCount = await Note.getCount();
|
|
|
|
|
|
2024-11-25 21:54:31 +01:00
|
|
|
serverLogger.info`Versia Server Worker started at ${config.http.bind}:${config.http.bind_port} in ${(performance.now() - timeAtStart).toFixed(0)}ms`;
|
2024-06-27 02:44:08 +02:00
|
|
|
|
2024-11-25 21:54:31 +01:00
|
|
|
serverLogger.info`Database is online, containing ${postCount} posts`;
|
2024-11-24 22:01:01 +01:00
|
|
|
|
|
|
|
|
// Check if Redis is reachable
|
|
|
|
|
const connection = new IORedis({
|
|
|
|
|
host: config.redis.queue.host,
|
|
|
|
|
port: config.redis.queue.port,
|
|
|
|
|
password: config.redis.queue.password,
|
|
|
|
|
db: config.redis.queue.database,
|
|
|
|
|
maxRetriesPerRequest: null,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await connection.ping();
|
|
|
|
|
|
|
|
|
|
serverLogger.info`Redis is online`;
|