init
This commit is contained in:
41
src/index.ts
Normal file
41
src/index.ts
Normal 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();
|
||||
|
||||
Reference in New Issue
Block a user