mirror of
https://codeberg.org/icewind/rss-webhook-trigger.git
synced 2026-06-03 18:04:09 +02:00
ctrl-c handling
This commit is contained in:
parent
6e13780297
commit
d70dbbedc3
3 changed files with 29 additions and 3 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -798,6 +798,15 @@ dependencies = [
|
|||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.3"
|
||||
|
|
@ -884,7 +893,9 @@ dependencies = [
|
|||
"memchr",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"tokio-macros",
|
||||
"winapi",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
rss = "1.10"
|
||||
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "json"] }
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "signal"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
toml = "0.5"
|
||||
|
|
|
|||
19
src/main.rs
19
src/main.rs
|
|
@ -11,6 +11,8 @@ use std::collections::hash_map::DefaultHasher;
|
|||
use std::collections::HashMap;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use tokio::time::sleep;
|
||||
use tokio::signal::ctrl_c;
|
||||
use tokio::select;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
|
|
@ -26,10 +28,23 @@ async fn main() -> Result<()> {
|
|||
};
|
||||
|
||||
let config = Config::from_file(&file)?;
|
||||
let mut fetcher = FeedFetcher::default();
|
||||
|
||||
println!("Running rss trigger for {} feeds", config.feed.len());
|
||||
|
||||
let ctrl_c = async { ctrl_c().await.ok(); };
|
||||
|
||||
select! {
|
||||
_ = ctrl_c => {},
|
||||
_ = main_loop(config) => {
|
||||
println!("more_async_work() completed first")
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn main_loop(config: Config) {
|
||||
let mut fetcher = FeedFetcher::default();
|
||||
|
||||
loop {
|
||||
for feed in config.feed.iter() {
|
||||
match fetcher.is_feed_updated(&feed.feed).await {
|
||||
|
|
@ -42,7 +57,7 @@ async fn main() -> Result<()> {
|
|||
if !feed.body.is_null() {
|
||||
req = req.json(&feed.body);
|
||||
}
|
||||
if let Err(e) = req.send().await?.error_for_status() {
|
||||
if let Err(e) = req.send().await.and_then(|res| res.error_for_status()) {
|
||||
eprintln!("{:#}", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue