mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(ActionScheduler): rename entry method into schedule
This commit is contained in:
@@ -53,7 +53,7 @@ public class ActionDispatcher extends PostRunningAbstractAgentModuleAbstract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
actionExecutor.execute(new ActionExecutorInput(immediateActions));
|
actionExecutor.execute(new ActionExecutorInput(immediateActions));
|
||||||
actionScheduler.execute(scheduledActions);
|
actionScheduler.schedule(scheduledActions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public class ActionExecutor extends AbstractAgentModule.Sub<ActionExecutorInput,
|
|||||||
// 如果是 ScheduledActionData, 则重置 ActionData 内容,记录执行历史与最终结果
|
// 如果是 ScheduledActionData, 则重置 ActionData 内容,记录执行历史与最终结果
|
||||||
if (executableAction instanceof SchedulableExecutableAction scheduledActionData) {
|
if (executableAction instanceof SchedulableExecutableAction scheduledActionData) {
|
||||||
scheduledActionData.recordAndReset();
|
scheduledActionData.recordAndReset();
|
||||||
actionScheduler.execute(Set.of(scheduledActionData));
|
actionScheduler.schedule(Set.of(scheduledActionData));
|
||||||
} else {
|
} else {
|
||||||
executableAction.setStatus(Status.SUCCESS);
|
executableAction.setStatus(Status.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ActionScheduler : AbstractAgentModule.Standalone() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun execute(input: Set<Schedulable>) = schedulerScope.launch {
|
fun schedule(input: Set<Schedulable>) = schedulerScope.launch {
|
||||||
for (schedulableData in input) {
|
for (schedulableData in input) {
|
||||||
log.debug("New data to schedule: {}", schedulableData)
|
log.debug("New data to schedule: {}", schedulableData)
|
||||||
timeWheel.schedule(schedulableData)
|
timeWheel.schedule(schedulableData)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class ActionSchedulerTest {
|
|||||||
|
|
||||||
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default + CoroutineName("ActionSchedulerTest"))
|
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default + CoroutineName("ActionSchedulerTest"))
|
||||||
scope.launch {
|
scope.launch {
|
||||||
actionScheduler.execute(
|
actionScheduler.schedule(
|
||||||
setOf(
|
setOf(
|
||||||
buildAction(now.plusSeconds(5)),
|
buildAction(now.plusSeconds(5)),
|
||||||
)
|
)
|
||||||
@@ -105,7 +105,7 @@ class ActionSchedulerTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `execute with null input should return null and no side effects`() {
|
fun `execute with null input should return null and no side effects`() {
|
||||||
// 场景编号:1;路径:B1;目的:验证正常早退
|
// 场景编号:1;路径:B1;目的:验证正常早退
|
||||||
val result = actionScheduler.execute(null)
|
val result = actionScheduler.schedule(null)
|
||||||
|
|
||||||
assertEquals(null, result)
|
assertEquals(null, result)
|
||||||
verify(actionCapability, Mockito.never()).putAction(any(ExecutableAction::class.java))
|
verify(actionCapability, Mockito.never()).putAction(any(ExecutableAction::class.java))
|
||||||
@@ -120,7 +120,7 @@ class ActionSchedulerTest {
|
|||||||
ZonedDateTime.now().plusHours(1).toString()
|
ZonedDateTime.now().plusHours(1).toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
actionScheduler.execute(setOf(action))
|
actionScheduler.schedule(setOf(action))
|
||||||
|
|
||||||
verify(actionCapability, times(1)).putAction(action)
|
verify(actionCapability, times(1)).putAction(action)
|
||||||
val timeWheel = timeWheel()
|
val timeWheel = timeWheel()
|
||||||
@@ -136,7 +136,7 @@ class ActionSchedulerTest {
|
|||||||
type = Schedulable.ScheduleType.ONCE
|
type = Schedulable.ScheduleType.ONCE
|
||||||
)
|
)
|
||||||
|
|
||||||
actionScheduler.execute(setOf(action))
|
actionScheduler.schedule(setOf(action))
|
||||||
|
|
||||||
verify(actionCapability, times(1)).putAction(action)
|
verify(actionCapability, times(1)).putAction(action)
|
||||||
val allScheduled = allScheduledActions(timeWheel())
|
val allScheduled = allScheduledActions(timeWheel())
|
||||||
@@ -151,7 +151,7 @@ class ActionSchedulerTest {
|
|||||||
type = Schedulable.ScheduleType.ONCE
|
type = Schedulable.ScheduleType.ONCE
|
||||||
)
|
)
|
||||||
|
|
||||||
actionScheduler.execute(setOf(action))
|
actionScheduler.schedule(setOf(action))
|
||||||
|
|
||||||
val allScheduled = allScheduledActions(timeWheel())
|
val allScheduled = allScheduledActions(timeWheel())
|
||||||
assertFalse(allScheduled.contains(action))
|
assertFalse(allScheduled.contains(action))
|
||||||
@@ -166,7 +166,7 @@ class ActionSchedulerTest {
|
|||||||
scheduleContentOverride = "invalid-cron"
|
scheduleContentOverride = "invalid-cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
actionScheduler.execute(setOf(action))
|
actionScheduler.schedule(setOf(action))
|
||||||
|
|
||||||
val allScheduled = allScheduledActions(timeWheel())
|
val allScheduled = allScheduledActions(timeWheel())
|
||||||
assertFalse(allScheduled.contains(action))
|
assertFalse(allScheduled.contains(action))
|
||||||
@@ -184,7 +184,7 @@ class ActionSchedulerTest {
|
|||||||
.putAction(action)
|
.putAction(action)
|
||||||
|
|
||||||
assertThrows(RuntimeException::class.java) {
|
assertThrows(RuntimeException::class.java) {
|
||||||
actionScheduler.execute(setOf(action))
|
actionScheduler.schedule(setOf(action))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ class ActionSchedulerTest {
|
|||||||
setCurrentHour(timeWheel, actionHour)
|
setCurrentHour(timeWheel, actionHour)
|
||||||
setWheelState(timeWheel, "SLEEPING")
|
setWheelState(timeWheel, "SLEEPING")
|
||||||
|
|
||||||
actionScheduler.execute(setOf(action))
|
actionScheduler.schedule(setOf(action))
|
||||||
|
|
||||||
assertEquals("ACTIVE", wheelStateName(timeWheel))
|
assertEquals("ACTIVE", wheelStateName(timeWheel))
|
||||||
}
|
}
|
||||||
@@ -225,7 +225,7 @@ class ActionSchedulerTest {
|
|||||||
scheduleContentOverride = "invalid-cron"
|
scheduleContentOverride = "invalid-cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
actionScheduler.execute(setOf(ok, nonPrepare, invalid))
|
actionScheduler.schedule(setOf(ok, nonPrepare, invalid))
|
||||||
|
|
||||||
verify(actionCapability, times(1)).putAction(ok)
|
verify(actionCapability, times(1)).putAction(ok)
|
||||||
verify(actionCapability, times(1)).putAction(nonPrepare)
|
verify(actionCapability, times(1)).putAction(nonPrepare)
|
||||||
|
|||||||
Reference in New Issue
Block a user