From 750bef0fd894217eb4bea3319e0c5ce0673a1d14 Mon Sep 17 00:00:00 2001 From: slhafzjw Date: Thu, 26 Mar 2026 15:18:46 +0800 Subject: [PATCH] refactor(action): add snapshot models and snapshot builders for Action/StateAction --- .../partner/core/action/entity/Action.kt | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/Partner-Core/src/main/java/work/slhaf/partner/core/action/entity/Action.kt b/Partner-Core/src/main/java/work/slhaf/partner/core/action/entity/Action.kt index 177e06cb..2c7fcc17 100644 --- a/Partner-Core/src/main/java/work/slhaf/partner/core/action/entity/Action.kt +++ b/Partner-Core/src/main/java/work/slhaf/partner/core/action/entity/Action.kt @@ -134,6 +134,28 @@ sealed class ExecutableAction : Action() { fun resume() { status = Status.EXECUTING } + + fun snapshot(): ExecutableActionSnapshot { + val schedulable = this as? Schedulable + + return ExecutableActionSnapshot( + uuid = uuid, + source = source, + reason = reason, + description = description, + timeoutMills = timeoutMills, + status = status, + tendency = tendency, + actionChainSize = actionChain.size, + executingStage = executingStage, + result = if (::result.isInitialized) result else null, + history = history.mapValues { (_, value) -> value.toList() }, + additionalContext = additionalContext.mapValues { (_, value) -> value.toList() }, + scheduleType = schedulable?.scheduleType, + scheduleContent = schedulable?.scheduleContent, + enabled = schedulable?.enabled + ) + } } /** @@ -201,6 +223,20 @@ data class StateAction @JvmOverloads constructor( override val timeout: Duration = 5.minutes, ) : Action(), Schedulable { + fun snapshot(): StateActionSnapshot { + return StateActionSnapshot( + uuid = uuid, + source = source, + reason = reason, + description = description, + timeoutMills = timeoutMills, + status = status, + scheduleType = scheduleType, + scheduleContent = scheduleContent, + enabled = enabled, + ) + } + sealed interface Trigger { fun onTrigger() @@ -225,3 +261,35 @@ data class StateAction @JvmOverloads constructor( } } + +data class ExecutableActionSnapshot( + val uuid: String, + val source: String, + val reason: String, + val description: String, + val timeoutMills: Long, + val status: Action.Status, + + val tendency: String, + val actionChainSize: Int, + val executingStage: Int, + val result: String?, + val history: Map>, + val additionalContext: Map>, + + val scheduleType: Schedulable.ScheduleType? = null, + val scheduleContent: String? = null, + val enabled: Boolean? = null +) + +data class StateActionSnapshot( + val uuid: String, + val source: String, + val reason: String, + val description: String, + val timeoutMills: Long, + val status: Action.Status, + val scheduleType: Schedulable.ScheduleType, + val scheduleContent: String, + val enabled: Boolean +) \ No newline at end of file