From 461c9e5ed23938720fa57b742d8ff69b920f136c Mon Sep 17 00:00:00 2001 From: "Aode (Lion)" Date: Wed, 6 Oct 2021 21:29:34 -0500 Subject: [PATCH] Port warn on drop from 0.9.x --- jobs-actix/src/worker.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/jobs-actix/src/worker.rs b/jobs-actix/src/worker.rs index 4567f77..039a2eb 100644 --- a/jobs-actix/src/worker.rs +++ b/jobs-actix/src/worker.rs @@ -56,6 +56,19 @@ impl Worker for LocalWorkerHandle { } } +struct LogOnDrop(F) +where + F: Fn() -> Span; + +impl Drop for LogOnDrop +where + F: Fn() -> Span, +{ + fn drop(&mut self) { + (self.0)().in_scope(|| info!("Worker closing")); + } +} + pub(crate) async fn local_worker( queue: String, processors: CachedProcessorMap, @@ -68,6 +81,8 @@ pub(crate) async fn local_worker( let handle = LocalWorkerHandle { tx, id, queue }; + let log_on_drop = LogOnDrop(|| handle.span("closing")); + loop { let span = handle.span("request"); if let Err(e) = server @@ -105,5 +120,5 @@ pub(crate) async fn local_worker( break; } - handle.span("closing").in_scope(|| info!("Worker closing")); + drop(log_on_drop); }