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)
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Warm-pings the Vercel RPC endpoint to populate the Redis cache.
|
|
* The RPC handler (list-service-statuses.ts) does the actual fetching
|
|
* and caching via cachedFetchJson. This script just triggers it.
|
|
*
|
|
* Standalone fallback — primary seeder is the AIS relay loop.
|
|
*/
|
|
|
|
import { loadEnvFile, CHROME_UA, getRedisCredentials, logSeedResult, extendExistingTtl } from './_seed-utils.mjs';
|
|
|
|
loadEnvFile(import.meta.url);
|
|
|
|
const RPC_URL = 'https://api.worldmonitor.app/api/infrastructure/v1/list-service-statuses';
|
|
const CANONICAL_KEY = 'infra:service-statuses:v1';
|
|
|
|
async function warmPing() {
|
|
const startMs = Date.now();
|
|
console.log('=== infra:service-statuses Warm Ping ===');
|
|
console.log(` Key: ${CANONICAL_KEY}`);
|
|
console.log(` Target: ${RPC_URL}`);
|
|
|
|
let data;
|
|
try {
|
|
const resp = await fetch(RPC_URL, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'User-Agent': CHROME_UA,
|
|
Origin: 'https://worldmonitor.app',
|
|
},
|
|
body: '{}',
|
|
signal: AbortSignal.timeout(60_000),
|
|
});
|
|
|
|
if (!resp.ok) throw new Error(`RPC failed: HTTP ${resp.status}`);
|
|
data = await resp.json();
|
|
} catch (err) {
|
|
console.error(` FETCH FAILED: ${err.message || err}`);
|
|
await extendExistingTtl([CANONICAL_KEY], 7200);
|
|
console.log(`\n=== Failed gracefully (${Math.round(Date.now() - startMs)}ms) ===`);
|
|
process.exit(0);
|
|
}
|
|
|
|
const count = data?.statuses?.length || 0;
|
|
console.log(` Statuses: ${count}`);
|
|
|
|
const { url, token } = getRedisCredentials();
|
|
const verifyResp = await fetch(`${url}/get/${encodeURIComponent(CANONICAL_KEY)}`, {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
signal: AbortSignal.timeout(5_000),
|
|
});
|
|
const verifyData = await verifyResp.json();
|
|
if (verifyData.result) {
|
|
console.log(' Verified: data present in Redis');
|
|
} else {
|
|
throw new Error('Verification failed: Redis key empty after successful RPC');
|
|
}
|
|
|
|
const durationMs = Date.now() - startMs;
|
|
logSeedResult('infra', count, durationMs, { mode: 'warm-ping' });
|
|
console.log(`\n=== Done (${Math.round(durationMs)}ms) ===`);
|
|
}
|
|
|
|
warmPing().then(() => {
|
|
process.exit(0);
|
|
}).catch((err) => {
|
|
console.error(`ERROR: ${err.message || err}`);
|
|
process.exit(1);
|
|
});
|