Add more logging

This commit is contained in:
Diggory Blake 2021-12-01 18:22:43 +00:00
parent ea408f7ab6
commit 592b7e6cb1
No known key found for this signature in database
GPG key ID: E6BDFA83146ABD40
3 changed files with 13 additions and 4 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "sqlxmq" name = "sqlxmq"
version = "0.3.3" version = "0.3.4"
authors = ["Diggory Blake <diggsey@googlemail.com>"] authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
@ -23,7 +23,7 @@ uuid = { version = "0.8.2", features = ["v4"] }
log = "0.4.14" log = "0.4.14"
serde_json = "1.0.64" serde_json = "1.0.64"
serde = "1.0.124" serde = "1.0.124"
sqlxmq_macros = { version = "0.3.3", path = "sqlxmq_macros" } sqlxmq_macros = { version = "0.3.4", path = "sqlxmq_macros" }
anymap2 = "0.13.0" anymap2 = "0.13.0"
[features] [features]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "sqlxmq_macros" name = "sqlxmq_macros"
version = "0.3.3" version = "0.3.4"
authors = ["Diggory Blake <diggsey@googlemail.com>"] authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View file

@ -4,6 +4,7 @@ use std::error::Error;
use std::fmt::Display; use std::fmt::Display;
use std::future::Future; use std::future::Future;
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant;
use anymap2::any::CloneAnySendSync; use anymap2::any::CloneAnySendSync;
use anymap2::Map; use anymap2::Map;
@ -83,7 +84,7 @@ impl JobRegistry {
/// The default error handler implementation, which simply logs the error. /// The default error handler implementation, which simply logs the error.
pub fn default_error_handler(name: &str, error: Box<dyn Error + Send + 'static>) { pub fn default_error_handler(name: &str, error: Box<dyn Error + Send + 'static>) {
log::error!("Job {} failed: {}", name, error); log::error!("Job `{}` failed: {}", name, error);
} }
#[doc(hidden)] #[doc(hidden)]
@ -94,8 +95,16 @@ impl JobRegistry {
) { ) {
let error_handler = self.error_handler.clone(); let error_handler = self.error_handler.clone();
tokio::spawn(async move { tokio::spawn(async move {
let start_time = Instant::now();
log::info!("Job `{}` started.", name);
if let Err(e) = f.await { if let Err(e) = f.await {
error_handler(name, e.into()); error_handler(name, e.into());
} else {
log::info!(
"Job `{}` completed in {}s.",
name,
start_time.elapsed().as_secs_f64()
);
} }
}); });
} }