refactor(ActionScheduler): support receiving single data that implements Schedulable and Action in ActionScheduler

This commit is contained in:
2026-03-07 15:30:25 +08:00
parent d9e384960f
commit ae1b7fc033
4 changed files with 24 additions and 31 deletions

View File

@@ -16,7 +16,6 @@ import work.slhaf.partner.module.modules.action.scheduler.ActionScheduler;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Phaser;
@@ -160,7 +159,7 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
// 如果是 ScheduledActionData, 则重置 ActionData 内容,记录执行历史与最终结果
if (executableAction instanceof SchedulableExecutableAction scheduledActionData) {
scheduledActionData.recordAndReset();
actionScheduler.schedule(Set.of(scheduledActionData));
actionScheduler.schedule(scheduledActionData);
} else {
executableAction.setStatus(Action.Status.SUCCESS);
}

View File

@@ -152,7 +152,7 @@ public class ActionPlanner extends PreRunningAbstractAgentModuleAbstract {
}
// execute or schedule it immediately
switch (executableAction) {
case SchedulableExecutableAction action -> actionScheduler.schedule(Set.of(action));
case SchedulableExecutableAction action -> actionScheduler.schedule(action);
case ImmediateExecutableAction action -> actionExecutor.execute(action);
default -> log.error("unknown executable action type: {}", executableAction.getClass().getSimpleName());
}

View File

@@ -70,16 +70,14 @@ class ActionScheduler : AbstractAgentModule.Standalone() {
// TODO any implementations of Action should be record into ActionCore
// TODO the method in ActionCapability should be compatible with different Action types
fun schedule(input: Set<Schedulable>) = schedulerScope.launch {
for (schedulableData in input) {
if (!schedulableData.enabled) {
continue
}
log.debug("New data to schedule: {}", schedulableData)
timeWheel.schedule(schedulableData)
if (schedulableData is SchedulableExecutableAction) {
actionCapability.putAction(schedulableData)
}
fun <T> schedule(schedulableAction: T) where T : Action, T : Schedulable = schedulerScope.launch {
if (!schedulableAction.enabled) {
return@launch
}
log.debug("New data to schedule: {}", schedulableAction)
timeWheel.schedule(schedulableAction)
if (schedulableAction is SchedulableExecutableAction) {
actionCapability.putAction(schedulableAction)
}
}