only fetch on demand
All checks were successful
CI/CD Pipeline / test (push) Successful in 3m47s
CI/CD Pipeline / deploy (push) Successful in 3m37s

This commit is contained in:
Philipp Hofer
2025-10-16 09:15:06 +02:00
parent f941eac386
commit 815590076d
3 changed files with 0 additions and 78 deletions

View File

@@ -1,10 +1,8 @@
use axum::{extract::State, http::HeaderMap, response::IntoResponse, routing::get, Router};
use chrono::Utc;
use player::Feed;
use reqwest::header;
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio_cron_scheduler::{Job, JobScheduler};
pub async fn stream_handler(State(state): State<Arc<RwLock<Feed>>>) -> impl IntoResponse {
state.write().await.fetch().await.unwrap();
@@ -24,22 +22,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.route("/", get(stream_handler))
.with_state(state.clone());
let scheduler = JobScheduler::new().await.unwrap();
scheduler
.add(
Job::new_async("0 0 */3 * * *", move |_uuid, _locked| {
let state_for_task = state.clone();
Box::pin(async move {
state_for_task.write().await.fetch().await.unwrap();
println!("Task executed at: {}", Utc::now());
})
})
.unwrap(),
)
.await
.unwrap();
scheduler.start().await.unwrap();
println!("Streaming server running on http://localhost:3029");
let listener = tokio::net::TcpListener::bind("0.0.0.0:3029").await?;