Skip to content

Commit

Permalink
expose main trace events as info/warn (0.2.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Sep 30, 2024
1 parent 3d5997c commit 2be9b65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# 0.2.2 (30. September, 2024)

Expose main trace events at Info level for increased visibility,
log-directives can be used by dependencies
to filter out tokio-graceful info events if not desired.

# 0.2.1 (30. September, 2024)

Expose a signal that can be awaited on without awaiting the configured
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
categories = ["asynchronous", "network-programming"]
edition = "2021"
name = "tokio-graceful"
version = "0.2.1"
version = "0.2.2"
description = "util for graceful shutdown of tokio applications"
homepage = "https://github.com/plabayo/tokio-graceful"
readme = "README.md"
Expand Down
18 changes: 9 additions & 9 deletions src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ impl Shutdown {
/// [`ShutdownGuard`]: crate::ShutdownGuard
/// [`Duration`]: std::time::Duration
pub async fn shutdown(mut self) -> time::Duration {
tracing::trace!("::shutdown: waiting for signal to trigger (read: to be cancelled)");
tracing::info!("::shutdown: waiting for signal to trigger (read: to be cancelled)");
let weak_guard = self.guard.downgrade();
let start: time::Instant = time::Instant::now();
tokio::select! {
_ = weak_guard.cancelled() => {
tracing::trace!("::shutdown: waiting for all guards to drop");
tracing::info!("::shutdown: waiting for all guards to drop");
}
_ = &mut self.zero_overwrite_rx => {
let elapsed = start.elapsed();
Expand All @@ -406,7 +406,7 @@ impl Shutdown {
tokio::select! {
_ = self.zero_rx => {
let elapsed = start.elapsed();
tracing::trace!("::shutdown: ready after {}s", elapsed.as_secs_f64());
tracing::info!("::shutdown: ready after {}s", elapsed.as_secs_f64());
elapsed
}
_ = self.zero_overwrite_rx => {
Expand Down Expand Up @@ -437,37 +437,37 @@ impl Shutdown {
mut self,
limit: time::Duration,
) -> Result<time::Duration, TimeoutError> {
tracing::trace!("::shutdown: waiting for signal to trigger (read: to be cancelled)");
tracing::info!("::shutdown: waiting for signal to trigger (read: to be cancelled)");
let weak_guard = self.guard.downgrade();
let start: time::Instant = time::Instant::now();
tokio::select! {
_ = weak_guard.cancelled() => {
tracing::trace!(
tracing::info!(
"::shutdown: waiting for all guards to drop for a max of {}s",
limit.as_secs_f64()
);
}
_ = &mut self.zero_overwrite_rx => {
let elapsed = start.elapsed();
tracing::trace!("::shutdown: enforced: overwrite delayed cancellation after {}s", elapsed.as_secs_f64());
tracing::warn!("::shutdown: enforced: overwrite delayed cancellation after {}s", elapsed.as_secs_f64());
return Err(TimeoutError(elapsed));
}
};

let start: time::Instant = time::Instant::now();
tokio::select! {
_ = tokio::time::sleep(limit) => {
tracing::trace!("::shutdown: timeout after {}s", limit.as_secs_f64());
tracing::info!("::shutdown: timeout after {}s", limit.as_secs_f64());
Err(TimeoutError(limit))
}
_ = self.zero_rx => {
let elapsed = start.elapsed();
tracing::trace!("::shutdown: ready after {}s", elapsed.as_secs_f64());
tracing::info!("::shutdown: ready after {}s", elapsed.as_secs_f64());
Ok(elapsed)
}
_ = self.zero_overwrite_rx => {
let elapsed = start.elapsed();
tracing::trace!("::shutdown: enforced: overwrite signal triggered after {}s", elapsed.as_secs_f64());
tracing::warn!("::shutdown: enforced: overwrite signal triggered after {}s", elapsed.as_secs_f64());
Err(TimeoutError(elapsed))
}
}
Expand Down

0 comments on commit 2be9b65

Please sign in to comment.