Skip to main content

dex_sdk/
reset_flow_options.rs

1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Super Durable Source License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
9use std::time::SystemTime;
10
11use crate::{Step, StepExecutionId};
12
13#[derive(Clone, Debug)]
14/// Selects a historical point from which [`crate::Client::reset_flow`] creates a new run.
15///
16/// Constructors identify exactly one reset point. Builder methods add an audit reason and control
17/// whether Channel messages and locking RPCs are reapplied. Both reapply switches default to
18/// `false`, so historical operations are reapplied.
19pub struct ResetFlowOptions {
20    pub(crate) point: ResetPoint,
21    pub(crate) reason: Option<String>,
22    pub(crate) skip_channel_messages_reapply: bool,
23    pub(crate) skip_locking_rpc_reapply: bool,
24}
25
26#[derive(Clone, Debug)]
27pub(crate) enum ResetPoint {
28    Beginning,
29    HistoryEventId(i64),
30    HistoryEventTime(SystemTime),
31    StepType(&'static str),
32    StepExecution(StepExecutionId),
33}
34
35impl ResetFlowOptions {
36    /// Resets before the first workflow-history event.
37    pub fn from_beginning() -> Self {
38        Self::new(ResetPoint::Beginning)
39    }
40
41    /// Resets at the specified server workflow-history event ID.
42    pub fn from_history_event_id(event_id: i64) -> Self {
43        Self::new(ResetPoint::HistoryEventId(event_id))
44    }
45
46    /// Resets at the last eligible history event at or before `event_time`.
47    pub fn from_history_event_time(event_time: SystemTime) -> Self {
48        Self::new(ResetPoint::HistoryEventTime(event_time))
49    }
50
51    /// Resets before the first execution of the selected Step type.
52    pub fn from_step<SomeStep: Step>(step: &SomeStep) -> Self {
53        Self::new(ResetPoint::StepType(step.step_type()))
54    }
55
56    /// Resets before the exact Step execution identified by `step_execution`.
57    pub fn from_step_execution(step_execution: StepExecutionId) -> Self {
58        Self::new(ResetPoint::StepExecution(step_execution))
59    }
60
61    /// Adds an operator-facing reason recorded with the reset.
62    pub fn reason(mut self, reason: impl Into<String>) -> Self {
63        self.reason = Some(reason.into());
64        self
65    }
66
67    /// Controls whether post-reset Channel messages are skipped instead of reapplied.
68    pub fn skip_channel_messages_reapply(mut self, skip: bool) -> Self {
69        self.skip_channel_messages_reapply = skip;
70        self
71    }
72
73    /// Controls whether post-reset locking RPCs are skipped instead of reapplied.
74    pub fn skip_locking_rpc_reapply(mut self, skip: bool) -> Self {
75        self.skip_locking_rpc_reapply = skip;
76        self
77    }
78
79    fn new(point: ResetPoint) -> Self {
80        Self {
81            point,
82            reason: None,
83            skip_channel_messages_reapply: false,
84            skip_locking_rpc_reapply: false,
85        }
86    }
87}