diff --git a/docker-compose.yaml b/docker-compose.yaml index e8358b3..424aae0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,10 +14,17 @@ services: image: git.georgew.dev/georgew/mission-control-worker:latest container_name: mc-worker restart: always + command: npx tsx scripts/update-space.ts volumes: - ./data:/app/data environment: - NODE_ENV=production + depends_on: + - mc-web + dns: + - 8.8.8.8 + - 1.1.1.1 + network_mode: "bridge" networks: web_traffic: diff --git a/scripts/update-space.ts b/scripts/update-space.ts index 88a0e8f..3c5badb 100644 --- a/scripts/update-space.ts +++ b/scripts/update-space.ts @@ -4,12 +4,11 @@ import path from 'path'; import fs from 'fs'; import { CosmicEvent } from '@/types/space'; - - const MY_LAT = 55.6683; const MY_LON = 12.5333; const MY_ALT = 0; + async function updateISSData() { console.log("🛰️ Fetching TLE data..."); @@ -154,15 +153,44 @@ async function updateAllData() { console.log("📡 Starting Ground Station sync..."); try { - await updateISSData(); - updateMoonPhase(); - updateCosmicEvents(); - await updateRocketLaunches(); + await updateISSData(); + } catch (e) { + console.error("⚠️ ISS sync failed (Timeout/Network)", e); + } - console.log("✅ All systems synchronized."); - } catch (error) { - console.error("❌ Sync failed:", error); + try { + updateMoonPhase(); + } catch (e) { + console.error("⚠️ Moon sync failed", e); + } + + try { + updateCosmicEvents(); + } catch (e) { + console.error("⚠️ Cosmic sync failed", e); + } + + try { + await updateRocketLaunches(); + } catch (e) { + console.error("⚠️ Rocket sync failed", e); } } -updateAllData().catch(console.error); +async function startWorker() { + console.log("🛰️ Ground Station Worker started..."); + + while (true) { + try { + await updateAllData(); + console.log("✅ Sync complete. Sleeping for 1 hour..."); + } catch (err) { + console.error("❌ Worker loop error:", err); + } + + // Sleep for 3600000ms (1 hour) + await new Promise(resolve => setTimeout(resolve, 3600000)); + } +} + +startWorker(); \ No newline at end of file