pub const SAGA: &str = "machine Saga<S> {\r\n state Planning(steps: Vec<S>)\r\n state Executing(steps: Vec<S>, index: i64, completed: Vec<S>)\r\n state Compensating(completed: Vec<S>, index: i64, reason: String)\r\n state Committed(completed: Vec<S>)\r\n state Aborted(reason: String, compensated_count: i64)\r\n\r\n transition begin: Planning -> Executing\r\n transition execute_next: Executing -> Executing | Compensating | Committed\r\n transition compensate_next: Compensating -> Compensating | Aborted\r\n\r\n async effect execute_forward(step: S) -> Result<S, String>\r\n async effect execute_compensate(step: S) -> Result<i64, String>\r\n effect len(steps: Vec<S>) -> i64\r\n effect get_step(steps: Vec<S>, index: i64) -> S\r\n effect push_step(steps: Vec<S>, step: S) -> Vec<S>\r\n effect empty_steps() -> Vec<S>\r\n\r\n on begin() {\r\n goto Executing(steps, 0, perform empty_steps());\r\n }\r\n\r\n async on execute_next() {\r\n if index >= perform len(steps) {\r\n goto Committed(completed);\r\n }\r\n\r\n let current = perform get_step(steps, index);\r\n let result = perform execute_forward(current);\r\n match result {\r\n Ok(done) => {\r\n let next_completed = perform push_step(completed, done);\r\n goto Executing(steps, index + 1, next_completed);\r\n }\r\n Err(err) => {\r\n goto Compensating(completed, perform len(completed) - 1, err);\r\n }\r\n }\r\n }\r\n\r\n async on compensate_next() {\r\n if index < 0 {\r\n goto Aborted(reason, perform len(completed));\r\n }\r\n\r\n let current = perform get_step(completed, index);\r\n let result = perform execute_compensate(current);\r\n match result {\r\n Ok(_) => {\r\n goto Compensating(completed, index - 1, reason);\r\n }\r\n Err(err) => {\r\n goto Aborted(err, perform len(completed) - index);\r\n }\r\n }\r\n }\r\n}\r\n";Expand description
The Gust source for the Saga machine.
Orchestrates a multi-step workflow with compensation. States include
Planning, Executing, Compensating, and Committed. If any step
fails during execution, the machine transitions to Compensating and
rolls back previously completed steps in reverse order.
Generic over S, the type representing individual saga steps.