From 227c735667b62e73fa64868e5eaa274e462c9e8c Mon Sep 17 00:00:00 2001 From: slhafzjw Date: Mon, 9 Feb 2026 00:13:36 +0800 Subject: [PATCH] fix(ActionScheduler): make TimeWheel load scheduled actions dynamically instead of using init snapshot --- .../dispatcher/scheduler/ActionScheduler.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Partner-Main/src/main/java/work/slhaf/partner/module/modules/action/dispatcher/scheduler/ActionScheduler.kt b/Partner-Main/src/main/java/work/slhaf/partner/module/modules/action/dispatcher/scheduler/ActionScheduler.kt index ee02d6cb..0796f60f 100644 --- a/Partner-Main/src/main/java/work/slhaf/partner/module/modules/action/dispatcher/scheduler/ActionScheduler.kt +++ b/Partner-Main/src/main/java/work/slhaf/partner/module/modules/action/dispatcher/scheduler/ActionScheduler.kt @@ -48,15 +48,18 @@ class ActionScheduler : AgentRunningSubModule, Void>() @Init fun init() { - val actions = actionCapability.listActions(null, null) - .stream() - .filter { actionData -> actionData is ScheduledActionData } - .map { actionData -> actionData as ScheduledActionData } - .collect(Collectors.toSet()) - timeWheel = TimeWheel(actions) { actionDataSet -> - actionExecutor.execute(ActionExecutorInput(actionDataSet)) + val listScheduledActions: () -> Set = { + actionCapability.listActions(null, null) + .stream() + .filter { it is ScheduledActionData } + .map { it as ScheduledActionData } + .collect(Collectors.toSet()) } + val onTrigger: (Set) -> Unit = { actionExecutor.execute(ActionExecutorInput(it)) } + + timeWheel = TimeWheel(listScheduledActions, onTrigger) + setupShutdownHook() } @@ -80,8 +83,8 @@ class ActionScheduler : AgentRunningSubModule, Void>() } private class TimeWheel( - val primaryActions: Set, - val onTrigger: (Set) -> Unit + val listScheduledActions: () -> Set, + val onTrigger: (toTrigger: Set) -> Unit ) : Closeable { private val actionsGroupByHour = Array>(24) { mutableSetOf() } @@ -232,7 +235,7 @@ class ActionScheduler : AgentRunningSubModule, Void>() ) { val runLoading = { val now = ZonedDateTime.now() - for (actionData in primaryActions) { + for (actionData in listScheduledActions()) { val latestExecutingTime = parseToZonedDateTime( actionData.scheduleType,