auto execute every 3 hours
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -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?;
|
||||
|
||||
Reference in New Issue
Block a user