mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-22 03:51:00 +00:00
Port warn on drop from 0.9.x
This commit is contained in:
parent
c0ce6f303e
commit
461c9e5ed2
1 changed files with 16 additions and 1 deletions
|
@ -56,6 +56,19 @@ impl Worker for LocalWorkerHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LogOnDrop<F>(F)
|
||||||
|
where
|
||||||
|
F: Fn() -> Span;
|
||||||
|
|
||||||
|
impl<F> Drop for LogOnDrop<F>
|
||||||
|
where
|
||||||
|
F: Fn() -> Span,
|
||||||
|
{
|
||||||
|
fn drop(&mut self) {
|
||||||
|
(self.0)().in_scope(|| info!("Worker closing"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn local_worker<State>(
|
pub(crate) async fn local_worker<State>(
|
||||||
queue: String,
|
queue: String,
|
||||||
processors: CachedProcessorMap<State>,
|
processors: CachedProcessorMap<State>,
|
||||||
|
@ -68,6 +81,8 @@ pub(crate) async fn local_worker<State>(
|
||||||
|
|
||||||
let handle = LocalWorkerHandle { tx, id, queue };
|
let handle = LocalWorkerHandle { tx, id, queue };
|
||||||
|
|
||||||
|
let log_on_drop = LogOnDrop(|| handle.span("closing"));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let span = handle.span("request");
|
let span = handle.span("request");
|
||||||
if let Err(e) = server
|
if let Err(e) = server
|
||||||
|
@ -105,5 +120,5 @@ pub(crate) async fn local_worker<State>(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.span("closing").in_scope(|| info!("Worker closing"));
|
drop(log_on_drop);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue