Skip to content

Commit 5f9133f

Browse files
committed
quality: fmt and unused import
1 parent ee4331d commit 5f9133f

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

crates/spfs-cli/cmd-monitor/src/cmd_monitor.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@ use clap::Parser;
88
#[cfg(feature = "sentry")]
99
use cli::configure_sentry;
1010
use miette::{Context, IntoDiagnostic, Result};
11-
use spfs::Error;
1211
use spfs_cli_common as cli;
1312
use spfs_cli_common::CommandName;
1413
use tokio::io::AsyncReadExt;
15-
#[cfg(unix)]
16-
use tokio::signal::unix::{signal, SignalKind};
17-
#[cfg(windows)]
18-
use tokio::signal::windows::ctrl_c;
1914
use tokio::time::timeout;
2015

2116
mod signal;
2217
#[cfg(unix)]
2318
use signal::unix_signal_handler::UnixSignalHandler as SignalHandlerImpl;
19+
use signal::SignalHandler;
2420
#[cfg(windows)]
2521
use windows_signal_handler::WindowsSignalHandler as SignalHandlerImpl;
2622

27-
use signal::SignalHandler;
28-
29-
30-
3123
fn main() -> Result<()> {
3224
// because this function exits right away it does not
3325
// properly handle destruction of data, so we put the actual
@@ -155,15 +147,15 @@ impl CmdMonitor {
155147

156148
pub async fn run_async(&mut self, config: &spfs::Config) -> Result<i32> {
157149
let signal_future = SignalHandlerImpl::build_signal_future();
158-
150+
159151
let repo = spfs::open_repository(&self.runtime_storage).await?;
160152
let storage = spfs::runtime::Storage::new(repo)?;
161153
let runtime = storage.read_runtime(&self.runtime).await?;
162154
tracing::trace!("read runtime from storage repo");
163-
155+
164156
let mut owned = spfs::runtime::OwnedRuntime::upgrade_as_monitor(runtime).await?;
165157
tracing::trace!("upgraded to owned runtime, waiting for empty runtime");
166-
158+
167159
let fut = spfs::monitor::wait_for_empty_runtime(&owned, config);
168160
let res = tokio::select! {
169161
res = fut => {
@@ -175,13 +167,13 @@ impl CmdMonitor {
175167
_ = signal_future => Err(spfs::Error::String("Signal received, cleaning up runtime early".to_string())),
176168
};
177169
tracing::trace!("runtime empty of processes ");
178-
170+
179171
// need to reload the runtime here to get any changes made to
180172
// the runtime while it was running so we don't blast them the
181173
// next time this process saves the runtime state.
182174
tracing::trace!("reloading runtime data before cleanup");
183175
owned.reload_state_from_storage().await?;
184-
176+
185177
// try to set the running to false to make this
186178
// runtime easier to identify as safe to delete
187179
// if the automatic cleanup fails. Any error
@@ -190,12 +182,12 @@ impl CmdMonitor {
190182
if let Err(err) = owned.save_state_to_storage().await {
191183
tracing::error!("failed to save runtime: {err:?}");
192184
}
193-
185+
194186
tracing::trace!("tearing down and exiting");
195187
if let Err(err) = spfs::exit_runtime(&owned).await {
196188
tracing::error!("failed to tear down runtime: {err:?}");
197189
}
198-
190+
199191
tracing::trace!(
200192
"{} runtime data",
201193
if owned.is_durable() {
@@ -216,7 +208,7 @@ impl CmdMonitor {
216208
} else if let Err(err) = owned.delete().await {
217209
tracing::error!("failed to clean up runtime data: {err:?}")
218210
}
219-
211+
220212
res?;
221213
Ok(0)
222214
}

crates/spfs-cli/cmd-monitor/src/signal.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use futures::future::Future;
21
use std::pin::Pin;
2+
3+
use futures::future::Future;
34
use spfs::Error;
45

56
pub trait SignalHandler {
@@ -8,9 +9,10 @@ pub trait SignalHandler {
89

910
#[cfg(unix)]
1011
pub mod unix_signal_handler {
11-
use super::*;
1212
use tokio::signal::unix::{signal, SignalKind};
1313

14+
use super::*;
15+
1416
pub struct UnixSignalHandler;
1517

1618
impl SignalHandler for UnixSignalHandler {
@@ -38,20 +40,21 @@ pub mod unix_signal_handler {
3840

3941
#[cfg(windows)]
4042
pub mod windows_signal_handler {
41-
use super::*;
4243
use tokio::signal::ctrl_c;
4344

45+
use super::*;
46+
4447
pub struct WindowsSignalHandler;
4548

4649
impl SignalHandler for WindowsSignalHandler {
4750
fn build_signal_future() -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> {
4851
Box::pin(async move {
49-
let mut interrupt = ctrl_c()
50-
.map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
51-
let mut quit = ctrl_c()
52-
.map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
53-
let mut terminate = ctrl_c()
54-
.map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
52+
let mut interrupt =
53+
ctrl_c().map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
54+
let mut quit =
55+
ctrl_c().map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
56+
let mut terminate =
57+
ctrl_c().map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
5558

5659
futures::future::select_all(vec![
5760
Box::pin(interrupt),
@@ -64,4 +67,4 @@ pub mod windows_signal_handler {
6467
})
6568
}
6669
}
67-
}
70+
}

0 commit comments

Comments
 (0)