1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2026 Super Durable, Inc.
//
// Licensed under the Sustainable Use License 1.0.
// You may not use this file except in compliance with the License.
// See the LICENSE file in the repository root.
//
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
use std::time::SystemTime;
use crate::{Step, StepExecutionId};
#[derive(Clone, Debug)]
/// Selects a historical point from which [`crate::Client::time_travel`] re-runs a Flow.
///
/// Time travel keeps the run ID and starts the next run attempt of that run.
///
/// Constructors identify exactly one time travel point. Builder methods add an audit reason and control
/// whether writes are reapplied. Write reapplication defaults to enabled.
pub struct TimeTravelOptions {
pub(crate) point: TimeTravelPoint,
pub(crate) reason: Option<String>,
pub(crate) skip_writes_reapply: bool,
}
#[derive(Clone, Debug)]
pub(crate) enum TimeTravelPoint {
Beginning,
HistoryEventTime(SystemTime),
StepType(&'static str),
StepExecution(StepExecutionId, TimeTravelStepMethod),
}
#[derive(Clone, Copy, Debug)]
/// Selects the Step method used as a Step execution time travel boundary.
pub enum TimeTravelStepMethod {
/// Reruns WaitFor and everything after it.
WaitFor,
/// Keeps the WaitFor result and reruns Execute and everything after it.
Execute,
}
impl TimeTravelOptions {
/// Resumes before the first workflow-history event.
pub fn from_beginning() -> Self {
Self::new(TimeTravelPoint::Beginning)
}
/// Resumes at the last eligible history event at or before `event_time`.
pub fn from_history_event_time(event_time: SystemTime) -> Self {
Self::new(TimeTravelPoint::HistoryEventTime(event_time))
}
/// Resumes before the first execution of the selected Step type.
pub fn from_step<SomeStep: Step>(step: &SomeStep) -> Self {
Self::new(TimeTravelPoint::StepType(step.step_type()))
}
/// Resumes before one method of the exact Step execution identified by `step_execution`.
pub fn from_step_execution(
step_execution: StepExecutionId,
method: TimeTravelStepMethod,
) -> Self {
Self::new(TimeTravelPoint::StepExecution(step_execution, method))
}
/// Adds an operator-facing reason recorded with time travel.
pub fn reason(mut self, reason: impl Into<String>) -> Self {
self.reason = Some(reason.into());
self
}
/// Controls whether later RPCs, Channel publications, and Attribute writes are skipped.
pub fn skip_writes_reapply(mut self, skip: bool) -> Self {
self.skip_writes_reapply = skip;
self
}
fn new(point: TimeTravelPoint) -> Self {
Self {
point,
reason: None,
skip_writes_reapply: false,
}
}
}