Files
Astronome/backend/src/jobs/weather_poll.rs
T
2026-04-09 23:23:31 +02:00

30 lines
869 B
Rust

use sqlx::SqlitePool;
use tokio::time::{sleep, Duration};
use crate::weather::poll_weather;
pub fn start_weather_scheduler(pool: SqlitePool) {
// 3-hour weather poll
let pool_3h = pool.clone();
tokio::spawn(async move {
loop {
if let Err(e) = poll_weather(&pool_3h).await {
tracing::error!("Weather poll (3h) failed: {}", e);
}
sleep(Duration::from_secs(3 * 3600)).await;
}
});
// 15-minute dew point poll (open-meteo only)
tokio::spawn(async move {
loop {
sleep(Duration::from_secs(15 * 60)).await;
if let Err(e) = crate::weather::openmeteo::fetch_openmeteo().await {
tracing::warn!("Dew point poll failed: {}", e);
} else {
tracing::debug!("Dew point poll OK");
}
}
});
}