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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! Cross-region rollout background dispatch: pre-flight a region, then
//! dispatch the deploy to it. The `:rollout` state machine in `msg.rs`
//! drives these — `spawn_rollout_preflight` per region first (so the
//! operator sees which regions pass before pressing `y`), then
//! `spawn_rollout_dispatch` per region sequentially, advancing or
//! halting on each `AppMsg::RolloutDispatched` result.
//!
//! `spawn_rollout_dispatch` reuses the shared `deploy_poll::decide_poll`
//! state machine for the optional wait-for-green, the same one the
//! `ebman action deploy/rollout` CLI path uses.
//!
//! 0.21+ lift: cluster moved out of `src/app.rs` as part of the
//! `spawn_*` clusters refactor. Pure relocation; kept `pub(crate)`
//! since these are referenced by name from `msg.rs` / `cmd_action.rs`.
//! No behaviour change.
use super::{App, AppMsg};
impl App {
/// Pre-flight one region of a rollout: construct an
/// AwsClient with the region override, list the region's
/// envs, check whether the target env exists, and emit
/// `AppMsg::RolloutPreflight`. Failure modes (STS error,
/// list_environments failure, env not found) all land as
/// per-region row state — the operator sees which regions
/// passed pre-flight and which need investigation before
/// pressing `y` to dispatch.
pub(crate) fn spawn_rollout_preflight(
&self,
profile: Option<String>,
region: String,
env_name: String,
) {
let tx = self.msg_tx.clone();
let gen = self.generation;
tokio::spawn(async move {
let result = match crate::aws::AwsClient::with(profile, Some(region.clone())).await {
Ok(client) => match client.list_environments().await {
Ok(envs) => match envs.iter().find(|e| e.name == env_name) {
Some(e) => Ok(e.version_label.clone()),
None => Err(format!("env '{env_name}' not found in region '{region}'")),
},
Err(e) => Err(format!("list_environments: {e}")),
},
Err(e) => Err(format!("AwsClient::with({region}): {e}")),
};
let _ = tx.send(AppMsg::RolloutPreflight {
gen,
region,
result,
});
});
}
/// Dispatch a single region of a rollout: construct an
/// AwsClient with that region's override, fire
/// `UpdateEnvironment(env, version_label)`, optionally poll
/// for Green if `wait_for_green_secs` is set. Emits
/// `AppMsg::RolloutDispatched` with the outcome. The handler
/// advances the state machine (next region, or halt on
/// failure).
///
/// Reuses `deploy_settled_green` for the wait-for-green
/// predicate. Polling cadence 5s; deadline `wait_for_green_secs`
/// from the dispatch's start.
pub(crate) fn spawn_rollout_dispatch(
&mut self,
rollout_id: String,
profile: Option<String>,
region: String,
env_name: String,
version_label: String,
wait_for_green_secs: Option<u64>,
) {
// Dispatch-time re-check (same defense-in-depth as
// `spawn_action`): read-only / freeze / incident / pins may
// have changed since the plan was confirmed, and the
// continuation path re-enters here for every region.
if self.deny_write(&env_name, "rollout") {
if let Some(crate::mode_action::ActionFlow::Rollout(flow)) = self.action_flow.as_mut() {
flow.state = crate::mode_action::RolloutState::Done;
}
return;
}
crate::audit::append_rollout(
&rollout_id,
®ion,
&env_name,
&version_label,
"dispatched",
None,
);
let tx = self.msg_tx.clone();
let gen = self.generation;
tokio::spawn(async move {
let client = match crate::aws::AwsClient::with(profile, Some(region.clone())).await {
Ok(c) => c,
Err(e) => {
let _ = tx.send(AppMsg::RolloutDispatched {
gen,
region,
result: Err(format!("client: {e}")),
});
return;
}
};
if let Err(e) = client.deploy_version(&env_name, &version_label).await {
let _ = tx.send(AppMsg::RolloutDispatched {
gen,
region,
result: Err(format!("deploy_version: {e}")),
});
return;
}
if let Some(secs) = wait_for_green_secs {
let start = tokio::time::Instant::now();
// Always false in this path — the WaitForGreenTimeout
// arm sends RolloutDispatched and returns
// immediately, so the per-tick suppression never
// fires. A future change wiring --auto-rollback for
// TUI rollouts will need to promote this to `let mut`
// so subsequent ticks suppress duplicate timeout
// milestones.
let wait_timeout_emitted = false;
loop {
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
let (status, health) = match client.list_environments().await {
Ok(envs) => envs
.iter()
.find(|e| e.name == env_name)
.map(|e| (e.status.clone(), e.health.clone()))
.unwrap_or_default(),
Err(e) => {
let _ = tx.send(AppMsg::RolloutDispatched {
gen,
region,
result: Err(format!("poll list_environments: {e}")),
});
return;
}
};
let elapsed = start.elapsed().as_secs();
match crate::deploy_poll::decide_poll(
&status,
&health,
elapsed,
Some(secs),
None,
wait_timeout_emitted,
) {
crate::deploy_poll::PollDecision::KeepPolling => {}
crate::deploy_poll::PollDecision::Success => break,
crate::deploy_poll::PollDecision::WaitForGreenTimeout => {
let _ = tx.send(AppMsg::RolloutDispatched {
gen,
region,
result: Err(format!(
"did not reach Green within {secs}s (status={status}, health={health})"
)),
});
return;
}
crate::deploy_poll::PollDecision::DispatchRollback => {
// --auto-rollback isn't wired into the
// TUI rollout path yet; defensive break
// in case a future change wires it.
break;
}
}
}
}
let _ = tx.send(AppMsg::RolloutDispatched {
gen,
region,
result: Ok(()),
});
});
}
}