muster/application/
process_lifecycle.rs1use crate::domain::{
2 process::{ExitIntent, ProcessState},
3 pty::ExitOutcome,
4};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ExitDecision {
9 Retire,
11 Stop,
13 RestartNow,
15 RestartLater,
17 Settle(ProcessState),
19}
20
21pub struct ProcessLifecycle;
23
24impl ProcessLifecycle {
25 pub fn after_exit(
27 intent: ExitIntent,
28 retired_by_config: bool,
29 should_restart: bool,
30 outcome: ExitOutcome,
31 ) -> ExitDecision {
32 if retired_by_config {
33 return ExitDecision::Retire;
34 }
35 match intent {
36 ExitIntent::StopRetryable | ExitIntent::StopInFlight => ExitDecision::Stop,
37 ExitIntent::RestartRetryable | ExitIntent::RestartInFlight => ExitDecision::RestartNow,
38 ExitIntent::FollowPolicy if should_restart => ExitDecision::RestartLater,
39 ExitIntent::FollowPolicy => ExitDecision::Settle(exit_state(outcome)),
40 }
41 }
42}
43
44fn exit_state(outcome: ExitOutcome) -> ProcessState {
46 match outcome {
47 ExitOutcome::Succeeded => ProcessState::Exited,
48 ExitOutcome::Failed => ProcessState::Crashed,
49 }
50}