Background task manager #332

Merged
lx merged 35 commits from background-task-manager into main 2022-07-08 11:30:32 +00:00
2 changed files with 29 additions and 1 deletions
Showing only changes of commit 0837b3dacd - Show all commits

View file

@ -728,6 +728,23 @@ impl Worker for ResyncWorker {
"Block resync worker".into() "Block resync worker".into()
} }
fn info(&self) -> Option<String> {
let mut ret = vec![];
let qlen = self.manager.resync_queue_len().unwrap_or(0);
let elen = self.manager.resync_errors_len().unwrap_or(0);
if qlen > 0 {
ret.push(format!("{} blocks in queue", qlen));
}
if elen > 0 {
ret.push(format!("{} blocks in error state", elen));
}
if ret.len() > 0 {
Some(ret.join(", "))
} else {
None
}
}
async fn work( async fn work(
&mut self, &mut self,
_must_exit: &mut watch::Receiver<bool>, _must_exit: &mut watch::Receiver<bool>,

View file

@ -326,7 +326,18 @@ where
&mut self, &mut self,
_must_exit: &mut watch::Receiver<bool>, _must_exit: &mut watch::Receiver<bool>,
) -> Result<WorkerStatus, Error> { ) -> Result<WorkerStatus, Error> {
self.0.updater_loop_iter() let updater = self.0.clone();
tokio::task::spawn_blocking(move || {
for _i in 0..100 {
let s = updater.updater_loop_iter();
if !matches!(s, Ok(WorkerStatus::Busy)) {
return s;
}
}
Ok(WorkerStatus::Busy)
})
.await
.unwrap()
} }
async fn wait_for_work(&mut self, must_exit: &watch::Receiver<bool>) -> WorkerStatus { async fn wait_for_work(&mut self, must_exit: &watch::Receiver<bool>) -> WorkerStatus {