Skip to content

Commit d17df5f

Browse files
committed
feat: v3.7.0
1 parent ff1c024 commit d17df5f

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "server-manager"
3-
version = "3.6.0"
3+
version = "3.7.0"
44
readme = "README.md"
55
edition = "2024"
66
authors = ["root@ltpp.vip"]

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ let pid_file: String = "./process/test_pid.pid".to_string();
3535
let _ = fs::remove_file(&pid_file);
3636
let mut config = ServerManagerConfig::new(pid_file.clone());
3737
config
38-
.set_before_start_daemon_hook(|| async {
38+
.set_start_hook(|| async {
3939
println!("Before start daemon hook executed");
4040
})
41-
.set_before_stop_hook(|| async {
41+
.set_stop_hook(|| async {
4242
println!("Before stop hook executed");
4343
});
44-
let dummy_server = || async {
44+
let server = || async {
4545
tokio::time::sleep(Duration::from_secs(1)).await;
4646
};
47-
let manager = ServerManager::new(config, dummy_server);
47+
let manager = ServerManager::new(config, server);
4848
let res: ServerManagerResult = manager.start_daemon().await;
4949
println!("start_daemon {:?}", res);
5050
let res: ServerManagerResult = manager.stop().await;

src/cfg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ async fn test_start_executes_server_fn() {
88
let _ = fs::remove_file(&pid_file);
99
let mut config = ServerManagerConfig::new(pid_file.clone());
1010
config
11-
.set_before_start_daemon_hook(|| async {
11+
.set_start_hook(|| async {
1212
println!("Before start daemon hook executed");
1313
})
14-
.set_before_stop_hook(|| async {
14+
.set_stop_hook(|| async {
1515
println!("Before stop hook executed");
1616
});
17-
let dummy_server = || async {
17+
let server = || async {
1818
tokio::time::sleep(Duration::from_secs(1)).await;
1919
};
20-
let manager = ServerManager::new(config, dummy_server);
20+
let manager = ServerManager::new(config, server);
2121
let res: ServerManagerResult = manager.start_daemon().await;
2222
println!("start_daemon {:?}", res);
2323
let res: ServerManagerResult = manager.stop().await;

src/config/impl.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ impl ServerManagerConfig {
1313
self
1414
}
1515

16-
pub fn set_before_stop_hook<F, Fut>(&mut self, f: F) -> &mut Self
16+
pub fn set_stop_hook<F, Fut>(&mut self, f: F) -> &mut Self
1717
where
1818
F: Fn() -> Fut + Send + Sync + 'static,
1919
Fut: Future<Output = ()> + Send + 'static,
2020
{
21-
self.before_stop_hook = Arc::new(move || Box::pin(f()));
21+
self.stop_hook = Arc::new(move || Box::pin(f()));
2222
self
2323
}
2424

25-
pub fn set_before_start_daemon_hook<F, Fut>(&mut self, f: F) -> &mut Self
25+
pub fn set_start_hook<F, Fut>(&mut self, f: F) -> &mut Self
2626
where
2727
F: Fn() -> Fut + Send + Sync + 'static,
2828
Fut: Future<Output = ()> + Send + 'static,
2929
{
30-
self.before_start_daemon_hook = Arc::new(move || Box::pin(f()));
30+
self.start_hook = Arc::new(move || Box::pin(f()));
3131
self
3232
}
3333

3434
pub fn get_pid_file(&self) -> &str {
3535
&self.pid_file
3636
}
3737

38-
pub fn get_before_stop_hook(&self) -> &Hook {
39-
&self.before_stop_hook
38+
pub fn get_stop_hook(&self) -> &Hook {
39+
&self.stop_hook
4040
}
4141

42-
pub fn get_before_start_daemon_hook(&self) -> &Hook {
43-
&self.before_start_daemon_hook
42+
pub fn get_start_hook(&self) -> &Hook {
43+
&self.start_hook
4444
}
4545
}
4646

@@ -49,8 +49,8 @@ impl Default for ServerManagerConfig {
4949
let empty_hook: Hook = Arc::new(|| Box::pin(async {}));
5050
Self {
5151
pid_file: Default::default(),
52-
before_stop_hook: empty_hook.clone(),
53-
before_start_daemon_hook: empty_hook,
52+
stop_hook: empty_hook.clone(),
53+
start_hook: empty_hook,
5454
}
5555
}
5656
}

src/config/struct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct ServerManagerConfig {
88
/// Path to the PID file for process tracking.
99
pub(crate) pid_file: String,
1010
/// An asynchronous function to be called before stopping the server.
11-
pub(crate) before_stop_hook: Hook,
12-
/// An asynchronous function to be called before starting the server daemon.
13-
pub(crate) before_start_daemon_hook: Hook,
11+
pub(crate) stop_hook: Hook,
12+
/// An asynchronous function to be called before starting the server.
13+
pub(crate) start_hook: Hook,
1414
}

src/manager/impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ where
4141
///
4242
/// - `ServerManagerResult` - Operation result.
4343
pub async fn stop(&self) -> ServerManagerResult {
44-
(self.config.before_stop_hook)().await;
44+
(self.config.stop_hook)().await;
4545
let pid: i32 = self.read_pid_file()?;
4646
self.kill_process(pid)
4747
}
4848

4949
/// Starts the server in daemon (background) mode on Unix platforms.
5050
#[cfg(not(windows))]
5151
pub async fn start_daemon(&self) -> ServerManagerResult {
52-
(self.config.before_start_daemon_hook)().await;
52+
(self.config.start_hook)().await;
5353
if std::env::var(RUNNING_AS_DAEMON).is_ok() {
5454
self.write_pid_file()?;
5555
let rt: Runtime = Runtime::new()?;
@@ -72,7 +72,7 @@ where
7272
/// Starts the server in daemon (background) mode on Windows platforms.
7373
#[cfg(windows)]
7474
pub async fn start_daemon(&self) -> ServerManagerResult {
75-
(self.config.before_start_daemon_hook)().await;
75+
(self.config.start_hook)().await;
7676
use std::os::windows::process::CommandExt;
7777
if std::env::var(RUNNING_AS_DAEMON).is_ok() {
7878
self.write_pid_file()?;

0 commit comments

Comments
 (0)