refactor(Action): add attribute enabled status into Action, and update related collectToTrigger logic in ActionScheduler

This commit is contained in:
2026-03-06 14:15:51 +08:00
parent facc49a799
commit 6635d7aca2
2 changed files with 8 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ sealed interface Schedulable {
val scheduleType: ScheduleType val scheduleType: ScheduleType
val scheduleContent: String val scheduleContent: String
val uuid: String val uuid: String
var enabled: Boolean
enum class ScheduleType { enum class ScheduleType {
CYCLE, CYCLE,
@@ -116,6 +117,7 @@ data class SchedulableExecutableAction(
override val scheduleContent: String override val scheduleContent: String
) : ExecutableAction(), Schedulable { ) : ExecutableAction(), Schedulable {
override var enabled = true
val scheduleHistories = ArrayList<ScheduleHistory>() val scheduleHistories = ArrayList<ScheduleHistory>()
fun recordAndReset() { fun recordAndReset() {
@@ -163,6 +165,8 @@ data class StateAction(
override val scheduleType: Schedulable.ScheduleType, override val scheduleType: Schedulable.ScheduleType,
override val scheduleContent: String, override val scheduleContent: String,
override var enabled: Boolean = true,
val trigger: Trigger val trigger: Trigger
) : Action(), Schedulable { ) : Action(), Schedulable {

View File

@@ -81,6 +81,9 @@ class ActionScheduler : AbstractAgentModule.Standalone() {
fun schedule(input: Set<Schedulable>) = schedulerScope.launch { fun schedule(input: Set<Schedulable>) = schedulerScope.launch {
for (schedulableData in input) { for (schedulableData in input) {
if (!schedulableData.enabled) {
continue
}
log.debug("New data to schedule: {}", schedulableData) log.debug("New data to schedule: {}", schedulableData)
timeWheel.schedule(schedulableData) timeWheel.schedule(schedulableData)
if (schedulableData is SchedulableExecutableAction) { if (schedulableData is SchedulableExecutableAction) {
@@ -143,7 +146,7 @@ class ActionScheduler : AbstractAgentModule.Standalone() {
for (i in previousTick..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.filter { it.enabled })
val bucketUuids = bucket.asSequence().map { it.uuid }.toHashSet() val bucketUuids = bucket.asSequence().map { it.uuid }.toHashSet()
schedulableGroupByHour[triggerHour].removeIf { it.uuid in bucketUuids } schedulableGroupByHour[triggerHour].removeIf { it.uuid in bucketUuids }
bucket.clear() // 避免重复触发 bucket.clear() // 避免重复触发