Files
worldmonitor/scripts
Elie Habib 9211339d1c fix(seeds): prevent API quota burn and respect rate limits (#1167)
* fix(cyber): prevent AbuseIPDB quota burn when Redis rate check fails

The catch block in fetchAbuseIpDb() was falling through to the API call
when the Redis rate-limit check failed (e.g. Redis down, first run with
no key). With a 10-minute cron interval, this could exhaust the 100
calls/day free-plan limit in under 17 hours.

Now returns early with { ok: false, threats: [] } so the other 4 IOC
sources still seed normally while AbuseIPDB is safely skipped.

* fix(seeds): respect API rate limits and log fetch failures

1. seed-fire-detections.mjs: increase delay from 200ms to 6s between
   FIRMS API calls. Free tier allows 10 req/min; 27 calls at 200ms
   exceeded this and caused silent failures.

2. ais-relay.cjs (positive events): increase GDELT delay from 500ms to
   5.5s to respect the documented 1 req/5s rate limit.

3. ais-relay.cjs (cyber fetchers): replace 5 silent `catch { return [] }`
   blocks with `console.warn` logging so failures are visible in Railway
   logs. Dead code today (cyber loop disabled) but sets the right example
   for contributors.

* fix(seeds): extend FIRMS lock TTL and restore AbuseIPDB resilience

P1: seed-fire-detections.mjs — the 6s FIRMS pacing makes the job take
~162s minimum, exceeding the default 120s lock TTL. Extend lockTtlMs
to 300s (5 min) to prevent overlapping cron invocations.

P2: seed-cyber-threats.mjs — revert the early return on Redis rate-check
failure. A transient Redis blip should not permanently disable AbuseIPDB
for that run. Instead, log a warning and proceed with caution. The 2h
rate-limit interval + 10-min cron means at most 1 extra call per Redis
outage window, well within the 100/day budget.

* fix(wildfire): extend lock TTL to 10 min for worst-case FIRMS timeouts

27 calls × (6s pacing + 30s per-request timeout) = 972s worst case.
300s lock was still too short under partial upstream slowness.
2026-03-07 10:51:45 +04:00
..