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
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