only fetch on demand
This commit is contained in:
59
Cargo.lock
generated
59
Cargo.lock
generated
@@ -170,15 +170,6 @@ version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "croner"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c344b0690c1ad1c7176fe18eb173e0c927008fdaaa256e40dfd43ddd149c0843"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.5"
|
||||
@@ -659,17 +650,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@@ -745,7 +725,6 @@ dependencies = [
|
||||
"reqwest",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tokio-cron-scheduler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1223,21 +1202,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-cron-scheduler"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c71ce8f810abc9fabebccc30302a952f9e89c6cf246fafaf170fef164063141"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"croner",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.5.0"
|
||||
@@ -1326,21 +1290,9 @@ checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.34"
|
||||
@@ -1386,17 +1338,6 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2"
|
||||
dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
|
@@ -9,5 +9,4 @@ tokio = { version = "1", features = ["full"] }
|
||||
reqwest = { version = "0.12", features = ["stream", "json", "rustls-tls"], default-features = false }
|
||||
serde_json = "1"
|
||||
chrono = "0.4"
|
||||
tokio-cron-scheduler = "0.14"
|
||||
quick-xml = "0.38"
|
||||
|
18
src/main.rs
18
src/main.rs
@@ -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?;
|
||||
|
Reference in New Issue
Block a user