Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Diggsey committed Dec 1, 2021
1 parent ea408f7 commit 592b7e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlxmq"
version = "0.3.3"
version = "0.3.4"
authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -23,7 +23,7 @@ uuid = { version = "0.8.2", features = ["v4"] }
log = "0.4.14"
serde_json = "1.0.64"
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"

[features]
Expand Down
2 changes: 1 addition & 1 deletion sqlxmq_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlxmq_macros"
version = "0.3.3"
version = "0.3.4"
authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
11 changes: 10 additions & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::error::Error;
use std::fmt::Display;
use std::future::Future;
use std::sync::Arc;
use std::time::Instant;

use anymap2::any::CloneAnySendSync;
use anymap2::Map;
Expand Down Expand Up @@ -83,7 +84,7 @@ impl JobRegistry {

/// The default error handler implementation, which simply logs the error.
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)]
Expand All @@ -94,8 +95,16 @@ impl JobRegistry {
) {
let error_handler = self.error_handler.clone();
tokio::spawn(async move {
let start_time = Instant::now();
log::info!("Job `{}` started.", name);
if let Err(e) = f.await {
error_handler(name, e.into());
} else {
log::info!(
"Job `{}` completed in {}s.",
name,
start_time.elapsed().as_secs_f64()
);
}
});
}
Expand Down

0 comments on commit 592b7e6

Please sign in to comment.