This commit is contained in:
2026-01-01 15:12:52 +01:00
commit 7bc14d7bbc
8 changed files with 169 additions and 0 deletions

41
src/index.ts Normal file
View File

@@ -0,0 +1,41 @@
import "dotenv/config";
import cron from "node-cron";
import { syncPlayers } from "./sync";
import { syncMongoToFirebase } from "./syncReverse"; // new function
async function main() {
const args = process.argv.slice(2);
if (args.includes("--one-time")) {
console.log("🔹 Running one-time Mongo → Firebase sync...");
try {
await syncMongoToFirebase();
console.log("✅ One-time sync finished");
} catch (e) {
console.error("One-time sync error:", e);
}
process.exit(0); // exit after one-time run
}
// Default: cron + immediate run
console.log("Firebase → Mongo sync running (every 15 minutes)");
// Run immediately
try {
await syncPlayers();
} catch (e) {
console.error("Players sync error:", e);
}
// Schedule every 15 minutes
cron.schedule("*/15 * * * *", async () => {
try {
await syncPlayers();
} catch (e) {
console.error("Players sync error:", e);
}
});
}
main();