mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +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 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 {
|
||||||
|
|
||||||
|
|||||||
@@ -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() // 避免重复触发
|
||||||
|
|||||||
Reference in New Issue
Block a user