mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
fix(ActionScheduler): make TimeWheel load scheduled actions dynamically instead of using init snapshot
This commit is contained in:
@@ -48,15 +48,18 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
|
|||||||
|
|
||||||
@Init
|
@Init
|
||||||
fun init() {
|
fun init() {
|
||||||
val actions = actionCapability.listActions(null, null)
|
val listScheduledActions: () -> Set<ScheduledActionData> = {
|
||||||
|
actionCapability.listActions(null, null)
|
||||||
.stream()
|
.stream()
|
||||||
.filter { actionData -> actionData is ScheduledActionData }
|
.filter { it is ScheduledActionData }
|
||||||
.map { actionData -> actionData as ScheduledActionData }
|
.map { it as ScheduledActionData }
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
timeWheel = TimeWheel(actions) { actionDataSet ->
|
|
||||||
actionExecutor.execute(ActionExecutorInput(actionDataSet))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val onTrigger: (Set<ScheduledActionData>) -> Unit = { actionExecutor.execute(ActionExecutorInput(it)) }
|
||||||
|
|
||||||
|
timeWheel = TimeWheel(listScheduledActions, onTrigger)
|
||||||
|
|
||||||
setupShutdownHook()
|
setupShutdownHook()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +83,8 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class TimeWheel(
|
private class TimeWheel(
|
||||||
val primaryActions: Set<ScheduledActionData>,
|
val listScheduledActions: () -> Set<ScheduledActionData>,
|
||||||
val onTrigger: (Set<ScheduledActionData>) -> Unit
|
val onTrigger: (toTrigger: Set<ScheduledActionData>) -> Unit
|
||||||
) : Closeable {
|
) : Closeable {
|
||||||
|
|
||||||
private val actionsGroupByHour = Array<MutableSet<ScheduledActionData>>(24) { mutableSetOf() }
|
private val actionsGroupByHour = Array<MutableSet<ScheduledActionData>>(24) { mutableSetOf() }
|
||||||
@@ -232,7 +235,7 @@ class ActionScheduler : AgentRunningSubModule<Set<ScheduledActionData>, Void>()
|
|||||||
) {
|
) {
|
||||||
val runLoading = {
|
val runLoading = {
|
||||||
val now = ZonedDateTime.now()
|
val now = ZonedDateTime.now()
|
||||||
for (actionData in primaryActions) {
|
for (actionData in listScheduledActions()) {
|
||||||
val latestExecutingTime =
|
val latestExecutingTime =
|
||||||
parseToZonedDateTime(
|
parseToZonedDateTime(
|
||||||
actionData.scheduleType,
|
actionData.scheduleType,
|
||||||
|
|||||||
Reference in New Issue
Block a user