Merge branch 'fix-windows-signal' into 'master'

fix signal compiling on windows

See merge request famedly/conduit!126
next
Timo Kösters 2021-07-15 16:29:47 +00:00
commit f924ebf8a6
1 changed files with 15 additions and 7 deletions

View File

@ -543,11 +543,10 @@ impl Database {
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
pub async fn start_wal_clean_task(lock: &Arc<TokioRwLock<Self>>, config: &Config) { pub async fn start_wal_clean_task(lock: &Arc<TokioRwLock<Self>>, config: &Config) {
use tokio::{ use tokio::time::{interval, timeout};
select,
signal::unix::{signal, SignalKind}, #[cfg(unix)]
time::{interval, timeout}, use tokio::signal::unix::{signal, SignalKind};
};
use std::{ use std::{
sync::Weak, sync::Weak,
@ -562,10 +561,12 @@ impl Database {
tokio::spawn(async move { tokio::spawn(async move {
let mut i = interval(timer_interval); let mut i = interval(timer_interval);
#[cfg(unix)]
let mut s = signal(SignalKind::hangup()).unwrap(); let mut s = signal(SignalKind::hangup()).unwrap();
loop { loop {
select! { #[cfg(unix)]
tokio::select! {
_ = i.tick(), if do_timer => { _ = i.tick(), if do_timer => {
log::info!(target: "wal-trunc", "Timer ticked") log::info!(target: "wal-trunc", "Timer ticked")
} }
@ -573,7 +574,14 @@ impl Database {
log::info!(target: "wal-trunc", "Received SIGHUP") log::info!(target: "wal-trunc", "Received SIGHUP")
} }
}; };
#[cfg(not(unix))]
if do_timer {
i.tick().await;
log::info!(target: "wal-trunc", "Timer ticked")
} else {
// timer disabled, and there's no concept of signals on windows, bailing...
return;
}
if let Some(arc) = Weak::upgrade(&weak) { if let Some(arc) = Weak::upgrade(&weak) {
log::info!(target: "wal-trunc", "Rotating sync helpers..."); log::info!(target: "wal-trunc", "Rotating sync helpers...");
// This actually creates a very small race condition between firing this and trying to acquire the subsequent write lock. // This actually creates a very small race condition between firing this and trying to acquire the subsequent write lock.