Skip to content

Commit

Permalink
Silence warnings when tracing feature is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtzxporter committed May 29, 2024
1 parent 21f7c77 commit 1c57640
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- Added `SupervisorOptions` for Supervisor::start/start_link/child_spec.
- Ability to customize the process name of the registry (use at own risk).

### Fixed
- Fixed warnings when tracing feature is disabled.

# 0.1.18

### Added
Expand Down
4 changes: 3 additions & 1 deletion hydra/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::future::Future;

use std::sync::Once;
use std::time::Duration;

use serde::Deserialize;
Expand Down Expand Up @@ -58,13 +57,16 @@ pub trait Application: Sized + Send + 'static {

#[cfg(feature = "tracing")]
if Self::TRACING_SUBSCRIBE {
use std::sync::Once;

static TRACING_SUBSCRIBE_ONCE: Once = Once::new();

TRACING_SUBSCRIBE_ONCE.call_once(|| {
tracing_subscriber::fmt::init();
});
}

#[allow(unused_mut)]
let mut prev_hook: Option<_> = None;

#[cfg(feature = "tracing")]
Expand Down
3 changes: 3 additions & 0 deletions hydra/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ impl Registry {
#[cfg(feature = "tracing")]
tracing::info!(reason = ?reason, child_key = ?key, child_pid = ?pid, "Removed registered process");

#[cfg(not(feature = "tracing"))]
let _ = reason;

REGISTRY.alter(&self.name, |_, value| {
value.remove_if(&key, |_, value| *value == pid);
value
Expand Down
12 changes: 12 additions & 0 deletions hydra/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ impl Supervisor {
#[cfg(feature = "tracing")]
tracing::error!(reason = ?reason, child_id = ?self.children[index].spec.id, "Start error");

#[cfg(not(feature = "tracing"))]
let _ = reason;

return Err(ExitReason::from("failed_to_start_child"));
}
}
Expand Down Expand Up @@ -559,6 +562,9 @@ impl Supervisor {
#[cfg(feature = "tracing")]
tracing::error!(reason = ?reason, child_id = ?id, child_pid = ?self.children[index].pid, "Start error");

#[cfg(not(feature = "tracing"))]
let _ = reason;

self.children[index].restarting = true;

Supervisor::cast(Process::current(), TryAgainRestartId(id));
Expand All @@ -572,6 +578,9 @@ impl Supervisor {
#[cfg(feature = "tracing")]
tracing::error!(reason = ?reason, child_id = ?id, child_pid = ?self.children[index].pid, "Start error");

#[cfg(not(feature = "tracing"))]
let _ = reason;

self.children[index].restarting = true;

Supervisor::cast(Process::current(), TryAgainRestartId(id));
Expand All @@ -584,6 +593,9 @@ impl Supervisor {
#[cfg(feature = "tracing")]
tracing::error!(reason = ?reason, child_id = ?id, child_pid = ?self.children[index].pid, "Start error");

#[cfg(not(feature = "tracing"))]
let _ = reason;

self.children[index].restarting = true;

Supervisor::cast(Process::current(), TryAgainRestartId(id));
Expand Down

0 comments on commit 1c57640

Please sign in to comment.