Skip to content

Commit e7445b4

Browse files
refactor(procmgr): colocate startup order helper with ProcessManager
Move recompute_startup_order into process_manager.rs since only ProcessManager uses it; mod.rs keeps cross-module spawn/reload helpers.
1 parent 300c6e5 commit e7445b4

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

pkg/procmgr/rust/src/manager/mod.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ mod supervisor;
1212
use supervisor::RuntimeHandles;
1313

1414
use crate::config::ProcessDefinition;
15-
use crate::ordering;
1615
use crate::process::ManagedProcess;
1716
use anyhow::Result;
18-
use log::{debug, warn};
17+
use log::warn;
1918
use std::sync::Arc;
2019
use tokio::sync::mpsc;
2120
use tonic::Status;
@@ -123,34 +122,6 @@ fn spawn_watcher(proc: &mut ManagedProcess, tx: mpsc::Sender<ExitEvent>) {
123122
}
124123
}
125124

126-
struct StartupOrderResult {
127-
order: Vec<usize>,
128-
warnings: Vec<String>,
129-
}
130-
131-
fn recompute_startup_order(procs: &[ManagedProcess]) -> StartupOrderResult {
132-
let defs: Vec<ProcessDefinition> = procs
133-
.iter()
134-
.map(|p| ProcessDefinition {
135-
name: p.name().to_string(),
136-
config: p.config().clone(),
137-
})
138-
.collect();
139-
let result = ordering::resolve_order(&defs);
140-
if !result.skipped.is_empty() {
141-
warn!(
142-
"dependency cycle detected, skipping processes: {}",
143-
result.skipped.join(", ")
144-
);
145-
}
146-
let names: Vec<&str> = result.order.iter().map(|&i| procs[i].name()).collect();
147-
debug!("startup order: {}", names.join(" -> "));
148-
StartupOrderResult {
149-
order: result.order,
150-
warnings: result.warnings,
151-
}
152-
}
153-
154125
#[cfg(test)]
155126
mod tests {
156127
use super::*;

pkg/procmgr/rust/src/manager/process_manager.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::{
22
ExitEvent, PendingRestart, RuntimeHandles, Supervisor, find_index_by_name, queue_restart,
3-
recompute_startup_order, resolve_index, try_spawn_and_watch,
3+
resolve_index, try_spawn_and_watch,
44
};
55
use crate::command::{CreateResult, StartResult, StopResult};
6-
use crate::config::{self, ConfigLoader};
6+
use crate::config::{self, ConfigLoader, ProcessDefinition};
7+
use crate::ordering;
78
use crate::process::ManagedProcess;
89
use crate::shutdown;
910
use crate::uuid_gen::UuidGenerator;
@@ -242,3 +243,31 @@ impl ProcessManager {
242243
shutdown::shutdown_ordered(&mut procs, &order).await;
243244
}
244245
}
246+
247+
struct StartupOrderResult {
248+
order: Vec<usize>,
249+
warnings: Vec<String>,
250+
}
251+
252+
fn recompute_startup_order(procs: &[ManagedProcess]) -> StartupOrderResult {
253+
let defs: Vec<ProcessDefinition> = procs
254+
.iter()
255+
.map(|p| ProcessDefinition {
256+
name: p.name().to_string(),
257+
config: p.config().clone(),
258+
})
259+
.collect();
260+
let result = ordering::resolve_order(&defs);
261+
if !result.skipped.is_empty() {
262+
warn!(
263+
"dependency cycle detected, skipping processes: {}",
264+
result.skipped.join(", ")
265+
);
266+
}
267+
let names: Vec<&str> = result.order.iter().map(|&i| procs[i].name()).collect();
268+
debug!("startup order: {}", names.join(" -> "));
269+
StartupOrderResult {
270+
order: result.order,
271+
warnings: result.warnings,
272+
}
273+
}

0 commit comments

Comments
 (0)