auto execute every 3 hours
All checks were successful
CI/CD Pipeline / test (push) Successful in 2m1s
CI/CD Pipeline / deploy (push) Successful in 2m20s

This commit is contained in:
Philipp Hofer
2025-10-13 15:34:50 +02:00
parent bbc8cf2c80
commit c5fc5be4a6
3 changed files with 30 additions and 239 deletions

View File

@@ -2,8 +2,10 @@ mod state;
mod streamer;
use axum::{routing::get, Router};
use chrono::Utc;
use state::AppState;
use std::sync::Arc;
use tokio_cron_scheduler::{Job, JobScheduler};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -13,6 +15,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.route("/", get(streamer::stream_handler))
.with_state(state.clone());
let scheduler = JobScheduler::new().await.unwrap();
scheduler
.add(
Job::new_async("0 */3 * * *", move |_uuid, _locked| {
let state_for_task = state.clone();
Box::pin(async move {
state_for_task.update().await;
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?;