mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(Action): add attribute enabled status into Action, and update related collectToTrigger logic in ActionScheduler
This commit is contained in:
@@ -32,6 +32,7 @@ sealed interface Schedulable {
|
||||
val scheduleType: ScheduleType
|
||||
val scheduleContent: String
|
||||
val uuid: String
|
||||
var enabled: Boolean
|
||||
|
||||
enum class ScheduleType {
|
||||
CYCLE,
|
||||
@@ -116,6 +117,7 @@ data class SchedulableExecutableAction(
|
||||
override val scheduleContent: String
|
||||
) : ExecutableAction(), Schedulable {
|
||||
|
||||
override var enabled = true
|
||||
val scheduleHistories = ArrayList<ScheduleHistory>()
|
||||
|
||||
fun recordAndReset() {
|
||||
@@ -163,6 +165,8 @@ data class StateAction(
|
||||
override val scheduleType: Schedulable.ScheduleType,
|
||||
override val scheduleContent: String,
|
||||
|
||||
override var enabled: Boolean = true,
|
||||
|
||||
val trigger: Trigger
|
||||
) : Action(), Schedulable {
|
||||
|
||||
|
||||
@@ -81,6 +81,9 @@ class ActionScheduler : AbstractAgentModule.Standalone() {
|
||||
|
||||
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) {
|
||||
@@ -143,7 +146,7 @@ class ActionScheduler : AbstractAgentModule.Standalone() {
|
||||
for (i in previousTick..tick) {
|
||||
val bucket = wheel[i]
|
||||
if (bucket.isNotEmpty()) {
|
||||
toTrigger.addAll(bucket)
|
||||
toTrigger.addAll(bucket.filter { it.enabled })
|
||||
val bucketUuids = bucket.asSequence().map { it.uuid }.toHashSet()
|
||||
schedulableGroupByHour[triggerHour].removeIf { it.uuid in bucketUuids }
|
||||
bucket.clear() // 避免重复触发
|
||||
|
||||
Reference in New Issue
Block a user