mirror of
https://codeberg.org/icewind/rss-webhook-trigger.git
synced 2026-11-30 04:00:49 +01:00
fix not responding to interrupt
This commit is contained in:
parent
ae1ef0657a
commit
82aaf985ef
1 changed files with 9 additions and 2 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -13,8 +13,8 @@ use std::hash::{Hash, Hasher};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
|
||||||
use syndication::Feed;
|
use syndication::Feed;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
use tracing::{debug, error, info, instrument, warn};
|
use tracing::{debug, error, info, instrument, warn};
|
||||||
use ureq::http::header::{HeaderValue, USER_AGENT};
|
use ureq::http::header::{HeaderValue, USER_AGENT};
|
||||||
use ureq::http::Response;
|
use ureq::http::Response;
|
||||||
|
|
@ -69,7 +69,14 @@ fn main_loop(config: Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(config.interval());
|
interruptable_sleep(config.interval());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn interruptable_sleep(duration: Duration) {
|
||||||
|
let target = Instant::now() + duration;
|
||||||
|
while Instant::now() < target && RUNNING.load(Ordering::SeqCst) {
|
||||||
|
sleep(Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue