Skip to content

Commit c2b8ccd

Browse files
committed
refactor(ui): 移除不必要的debug打印并优化task运行逻辑
1 parent 6f2df6a commit c2b8ccd

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

silent/src/scheduler/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Result, anyhow};
88
use std::sync::{Arc, LazyLock};
99
use std::thread;
1010
use tokio::sync::Mutex;
11-
use tracing::{debug, error, info};
11+
use tracing::{error, info};
1212

1313
pub use process_time::ProcessTime;
1414
pub use task::Task;
@@ -75,10 +75,7 @@ impl Scheduler {
7575
if task.is_async {
7676
tokio::spawn(async move {
7777
match task.clone().run_async().await {
78-
Ok(_) => debug!(
79-
"task: ID:{:?} Description:{:?} ProcessTime:{:?} activate success!",
80-
task.id, task.description, task.process_time
81-
),
78+
Ok(_) => {}
8279
Err(e) => error!(
8380
"task: ID:{:?} Description:{:?} ProcessTime:{:?} run failed! error: {:?}",
8481
task.id, task.description, task.process_time, e
@@ -87,10 +84,7 @@ impl Scheduler {
8784
});
8885
} else {
8986
thread::spawn(move || match task.clone().run() {
90-
Ok(_) => debug!(
91-
"task: ID:{:?} Description:{:?} ProcessTime:{:?} activate success!",
92-
task.id, task.description, task.process_time
93-
),
87+
Ok(_) => {}
9488
Err(e) => error!(
9589
"task: ID:{:?} Description:{:?} ProcessTime:{:?} run failed! error: {:?}",
9690
task.id, task.description, task.process_time, e

silent/src/scheduler/task.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fmt::Debug;
55
use std::future::Future;
66
use std::pin::Pin;
77
use std::sync::Arc;
8+
use tracing::debug;
89

910
pub type JobToRun = dyn Fn() -> Result<()> + Send + Sync;
1011
pub type JobToRunAsync = dyn Fn() -> Pin<Box<dyn Future<Output = Result<()>> + Send>> + Send + Sync;
@@ -38,15 +39,27 @@ impl Task {
3839
match self.is_async {
3940
true => Err(anyhow::anyhow!("async task not support run")),
4041
false => match self.process_time.is_active() {
41-
true => self.action.clone()(),
42+
true => {
43+
debug!(
44+
"task: ID:{:?} Description:{:?} ProcessTime:{:?} activate success!",
45+
self.id, self.description, self.process_time
46+
);
47+
self.action.clone()()
48+
}
4249
false => Ok(()),
4350
},
4451
}
4552
}
4653
pub(crate) async fn run_async(&self) -> Result<()> {
4754
match self.is_async {
4855
true => match self.process_time.is_active() {
49-
true => self.action_async.clone()().await,
56+
true => {
57+
debug!(
58+
"async task: ID:{:?} Description:{:?} ProcessTime:{:?} activate success!",
59+
self.id, self.description, self.process_time
60+
);
61+
self.action_async.clone()().await
62+
}
5063
false => Ok(()),
5164
},
5265
false => Err(anyhow::anyhow!("sync task not support run_async")),

0 commit comments

Comments
 (0)