import { AppData } from "@/src/data/app-data";
import cronCheckServices from "./functions/check-services";
import { watchFile } from "fs";
import path from "path";
import { execSync } from "child_process";

if (process.env.NODE_ENV !== "production") {
    watchFile(path.resolve(__dirname, "../db/db-schema.js"), (curr, prev) => {
        execSync(`bunx nsqlite schema -t`, {
            cwd: path.resolve(__dirname, "../.."),
            stdio: "inherit",
        });
    });
}

while (true) {
    console.log(`Running Cron Services ...`);

    try {
        await cronCheckServices();
    } catch (error) {}

    await Bun.sleep(AppData["CronInterval"]);
}

// export {};
