Browse Source

设置等待时间,防止执行过快

JiahengHe 8 months ago
parent
commit
5bda2614a1
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/core_libs.rs

+ 8 - 5
src/core_libs.rs

@@ -144,14 +144,17 @@ pub async fn init(params: Params,
             // 计算需要等待的时间
             let wait_duration = next_hour - now;
             let wait_secs = wait_duration.num_seconds() as u64;
-
-
-            // 等待到下一个整点
-            sleep_until(Instant::now() + std::time::Duration::from_secs(wait_secs)).await;
-
+            
+            if wait_secs > 0 {
+                sleep_until(Instant::now() + Duration::from_secs(wait_secs)).await;
+            }
+            
             // 更新近7天的交易量统计
             let mut core = trade_volume_core_arc.lock().await;
             core.update_trade_volume().await;
+
+            // 等待一分钟以避免过快地循环
+            sleep_until(Instant::now() + Duration::from_secs(60)).await;
         }
     });