diff --git a/src/officesense_pi/src/core/bootstrap.ts b/src/officesense_pi/src/core/bootstrap.ts index a089428..551a67d 100644 --- a/src/officesense_pi/src/core/bootstrap.ts +++ b/src/officesense_pi/src/core/bootstrap.ts @@ -1,16 +1,27 @@ -import { initRedis } from "./redis.js"; +import { getRoomIDs } from "../api/livedata/livedata.repository.js"; +import { initRedis, initSubRedis } from "../redis/redis.js"; import * as mqtt from "./mqtt.js"; import { cleanupWorker } from "./transition.js"; export async function bootstrap() { try { - await initRedis(); + const redis = await initRedis(); + + await redis.flushDb(); + console.log(`[!] Flushed Redis.`); + + const rooms = await getRoomIDs(); + for (const { id } of rooms) + await redis.set(`room:${id}`, 0); + + await initSubRedis(); await mqtt.start(); + cleanupWorker(); - console.log("Core started."); + console.log("[!] Core started."); } catch (err: any) { - console.log("Bootstrap failed:", err.message); + console.log("[!] Bootstrap failed:", err.message); process.exit(1); } } \ No newline at end of file