From 8bac55b94302383927a61d9bc68cb028a6f8c026 Mon Sep 17 00:00:00 2001 From: WrBug Date: Wed, 3 Dec 2025 06:25:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=B7=9F=E5=8D=95?= =?UTF-8?q?=E8=BD=AE=E8=AF=A2=E8=87=AA=E5=8A=A8=E5=90=AF=E5=8A=A8/?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addLeader 时自动启动轮询任务(如果还没有运行) - removeLeader 时自动停止轮询任务(如果没有需要监听的 Leader) - 确保轮询任务根据跟单状态动态调整,避免不必要的资源消耗 --- .../polymarketbot/service/CopyTradingPollingService.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/CopyTradingPollingService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/CopyTradingPollingService.kt index 099d54d..e5f4a37 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/CopyTradingPollingService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/CopyTradingPollingService.kt @@ -78,6 +78,9 @@ class CopyTradingPollingService( cachedTradeIds[leaderId] = mutableSetOf() // 首次轮询标志,用于缓存数据而不处理 isFirstPoll[leaderId] = true + + // 如果轮询任务没有运行,启动它 + startPolling() } /** @@ -87,6 +90,11 @@ class CopyTradingPollingService( monitoredLeaders.remove(leaderId) cachedTradeIds.remove(leaderId) isFirstPoll.remove(leaderId) + + // 如果没有需要监听的Leader了,停止轮询任务 + if (monitoredLeaders.isEmpty()) { + stopPolling() + } } /**