mcp_stdio_proxy/server/task/
schedule_task.rs1use crate::server::task::schedule_check_mcp_live;
2use log::{debug, info, warn};
3use std::sync::Arc;
4use std::sync::atomic::{AtomicBool, Ordering};
5use tokio::time::{Duration, interval};
6
7pub async fn start_schedule_task() {
12 info!("Start the MCP service status check scheduled task");
13
14 let mut interval = interval(Duration::from_secs(20));
16
17 let is_running = Arc::new(AtomicBool::new(false));
19
20 tokio::spawn(async move {
22 loop {
23 interval.tick().await;
25
26 if is_running.load(Ordering::SeqCst) {
28 warn!(
29 "The last MCP service status check task has not been completed and this execution will be skipped."
30 );
31 continue;
32 }
33
34 is_running.store(true, Ordering::SeqCst);
36
37 debug!("Perform periodic checks on MCP service status...");
39
40 let is_running_clone = is_running.clone();
42 tokio::spawn(async move {
43 match tokio::time::timeout(
45 Duration::from_secs(10), schedule_check_mcp_live(),
47 )
48 .await
49 {
50 Ok(_) => {
51 debug!("MCP service status check completed");
52 }
53 Err(_) => {
54 warn!("MCP service status check task timed out");
55 }
56 }
57
58 is_running_clone.store(false, Ordering::SeqCst);
60 });
61 }
62 });
63
64 info!("MCP service status check scheduled task has been started");
65}