fix(ActionScheduler): include previous tick in trigger scan and tighten next execution filtering

This commit is contained in:
2026-02-09 21:01:22 +08:00
parent ecbbbc9954
commit 9ec03c4c95

View File

@@ -136,7 +136,7 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
fun collectToTrigger(tick: Int, previousTick: Int, triggerHour: Int): Set<ScheduledActionData>? { fun collectToTrigger(tick: Int, previousTick: Int, triggerHour: Int): Set<ScheduledActionData>? {
if (tick > previousTick) { if (tick > previousTick) {
val toTrigger = mutableSetOf<ScheduledActionData>() val toTrigger = mutableSetOf<ScheduledActionData>()
for (i in (previousTick + 1)..tick) { for (i in previousTick..tick) {
val bucket = wheel[i] val bucket = wheel[i]
if (bucket.isNotEmpty()) { if (bucket.isNotEmpty()) {
toTrigger.addAll(bucket) toTrigger.addAll(bucket)
@@ -193,13 +193,15 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
onTrigger(it) onTrigger(it)
log.debug("Executing action at hour {} tick {}", launchingHour, tick) log.debug("Executing action at hour {} tick {}", launchingHour, tick)
} }
// 休眠一秒
delay(1000)
if (shouldBreak) { if (shouldBreak) {
log.debug("Wheel stopped at tick {}", tick) log.debug("Wheel stopped at tick {}", tick)
break break
} }
// 休眠一秒
delay(1000)
} }
} }
@@ -253,7 +255,7 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
) { ) {
val runLoading = { val runLoading = {
for (actionData in source) { for (actionData in source) {
val latestExecutingTime = val nextExecutingTime =
parseToZonedDateTime( parseToZonedDateTime(
actionData.scheduleType, actionData.scheduleType,
actionData.scheduleContent, actionData.scheduleContent,
@@ -263,7 +265,7 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
continue continue
} }
load(latestExecutingTime, actionData) load(nextExecutingTime, actionData)
} }
} }
@@ -341,7 +343,7 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
} catch (_: Exception) { } catch (_: Exception) {
return null return null
} }
if (executionTime.isBefore(now) || executionTime.dayOfYear != now.dayOfYear) if (executionTime.plusSeconds(1).isBefore(now) || executionTime.dayOfMonth != now.dayOfMonth)
null null
else else
executionTime executionTime