server/entrypoints/worker/setup.ts

45 lines
1.8 KiB
TypeScript
Raw Normal View History

import { configureLoggers } from "@/loggers";
import { connection } from "@/redis.ts";
import { getLogger } from "@logtape/logtape";
import { Note } from "@versia/kit/db";
import chalk from "chalk";
import { config } from "~/config.ts";
import { setupDatabase } from "~/drizzle/db";
import { searchManager } from "../../classes/search/search-manager.ts";
const timeAtStart = performance.now();
await configureLoggers();
const serverLogger = getLogger("server");
console.info(`
${chalk.redBright.bold("** WORKER MODE **")}
`);
serverLogger.info`Starting Versia Server Worker...`;
await setupDatabase();
if (config.search.enabled) {
await searchManager.connect();
}
// Check if database is reachable
const postCount = await Note.getCount();
serverLogger.info`Versia Server Worker started at ${config.http.bind}:${config.http.bind_port} in ${(performance.now() - timeAtStart).toFixed(0)}ms`;
serverLogger.info`Database is online, containing ${postCount} posts`;
// Check if Redis is reachable
await connection.ping();
serverLogger.info`Redis is online`;