munger-engine / scripts /debug_sync_manual.ts
dromerosm's picture
feat: Implement secure sync button with live API status and adaptive polling
4435002
import { runSync } from '../lib/sync-service';
import { JsonStore } from '../lib/store';
async function main() {
console.log("Starting manual sync debug...");
// 1. Check initial status
console.log("Initial Status:", JsonStore.getStatus());
// 2. Trigger Sync
try {
console.log("Calling runSync()...");
const res = await runSync({ force: true });
console.log("runSync returned:", res);
} catch (e) {
console.error("runSync failed:", e);
}
// 3. Poll status for 10 seconds
const start = Date.now();
while (Date.now() - start < 10000) {
const status = JsonStore.getStatus();
console.log("Current Status:", status.status, `Analyzed: ${status.assetsAnalyzed}/${status.totalAssets}`);
if (status.status === 'IDLE' && status.assetsAnalyzed > 0) {
console.log("Sync finished early?");
break;
}
await new Promise(r => setTimeout(r, 1000));
}
console.log("Final Status:", JsonStore.getStatus());
}
main().catch(console.error);