mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-26 01:24:59 +02:00
* fix(seeds): improve resilience and fix dead APIs across seed scripts
- Fix wrong domain in seed-service-statuses (worldmonitor.app to api.worldmonitor.app)
- Fix Kalshi API domain migration (trading-api.kalshi.com to api.elections.kalshi.com)
- Replace dead trending APIs (gitterapp.com, herokuapp.com) with OSSInsight + GitHub Search
- Fix case-sensitive HTML detection in seed-usni-fleet (lowercase doctype not matched)
- Add Promise.allSettled rejection logging across 8 seed scripts
- Wrap fetch loops in try-catch (seed-supply-chain-trade, seed-economy) so a single
network error no longer kills the entire function
- Update list-trending-repos.ts RPC handler to match seed changes
* fix(seeds): correct OSSInsight response parsing and period-aware GitHub Search fallback
- OSSInsight returns {data: {rows: [...]}} not {data: [...]}, fix both seed and handler
- GitHub Search fallback now respects period parameter (daily=1d, weekly=7d, monthly=30d)
* fix(seeds): correct OSSInsight period values (past_week/past_month, not past_7_days/past_28_days)
69 lines
2.3 KiB
JavaScript
Executable File
69 lines
2.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Seed infrastructure data via warm-ping pattern.
|
|
*
|
|
* These handlers have complex logic (30 status page parsers, NGA text analysis)
|
|
* that is impractical to replicate in a standalone script. Instead, we call the
|
|
* Vercel RPC endpoints from Railway to warm-populate the Redis cache.
|
|
*
|
|
* Seeded via warm-ping:
|
|
* - list-service-statuses: pings 30 status pages, caches result
|
|
* - get-cable-health: NGA warning analysis, caches cable health map
|
|
*
|
|
* NOT seeded (inherently on-demand):
|
|
* - search-imagery: per-bbox/datetime STAC query (cache key is hash of params)
|
|
* - get-giving-summary: uses hardcoded baselines, NO external fetches
|
|
* - get-webcam-image: per-webcamId Windy API lookup
|
|
*/
|
|
|
|
import { loadEnvFile, CHROME_UA } from './_seed-utils.mjs';
|
|
|
|
loadEnvFile(import.meta.url);
|
|
|
|
const API_BASE = 'https://api.worldmonitor.app';
|
|
const TIMEOUT = 30_000;
|
|
|
|
async function warmPing(name, path) {
|
|
try {
|
|
const resp = await fetch(`${API_BASE}${path}`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'User-Agent': CHROME_UA, Origin: 'https://worldmonitor.app' },
|
|
body: JSON.stringify({}),
|
|
signal: AbortSignal.timeout(TIMEOUT),
|
|
});
|
|
if (!resp.ok) {
|
|
console.warn(` ${name}: HTTP ${resp.status}`);
|
|
return false;
|
|
}
|
|
const data = await resp.json();
|
|
const count = data.statuses?.length ?? (data.cables ? Object.keys(data.cables).length : 0);
|
|
console.log(` ${name}: OK (${count} items)`);
|
|
return true;
|
|
} catch (e) {
|
|
console.warn(` ${name}: ${e.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
console.log('=== Infrastructure Warm-Ping Seed ===');
|
|
const start = Date.now();
|
|
|
|
const results = await Promise.allSettled([
|
|
warmPing('Service Statuses', '/api/infrastructure/v1/list-service-statuses'),
|
|
warmPing('Cable Health', '/api/infrastructure/v1/get-cable-health'),
|
|
]);
|
|
|
|
for (const r of results) { if (r.status === 'rejected') console.warn(` Warm-ping failed: ${r.reason?.message || r.reason}`); }
|
|
|
|
const ok = results.filter(r => r.status === 'fulfilled' && r.value).length;
|
|
const total = results.length;
|
|
const duration = Date.now() - start;
|
|
|
|
console.log(`\n=== Done: ${ok}/${total} warm-pings OK (${duration}ms) ===`);
|
|
process.exit(ok > 0 ? 0 : 1);
|
|
}
|
|
|
|
main();
|