use std::time::Duration;
use crate::builder::IntoExpression;
use crate::error::CamelError;
use crate::model::RouteDefinition;
use crate::processor::saga::{SagaCompletionMode, SagaDefinition, SagaPropagation};
impl RouteDefinition {
pub fn saga(&mut self) -> &mut Self {
self.push_block(Box::new(SagaDefinition::new()))
}
fn with_saga(&mut self, option: &str, f: impl FnOnce(&mut SagaDefinition)) -> &mut Self {
match self.current_block_mut::<SagaDefinition>() {
Some(s) => f(s),
None => self.add_build_error(CamelError::illegal_argument(format!("{} must be used inside a saga block", option))),
}
self
}
pub fn propagation(&mut self, p: SagaPropagation) -> &mut Self {
self.with_saga("propagation", |s| s.propagation = p)
}
pub fn completion_mode(&mut self, m: SagaCompletionMode) -> &mut Self {
self.with_saga("completionMode", |s| s.completion_mode = m)
}
pub fn saga_timeout(&mut self, d: Duration) -> &mut Self {
self.with_saga("timeout", |s| s.timeout = Some(d))
}
pub fn compensation(&mut self, uri: impl Into<String>) -> &mut Self {
let uri = uri.into();
self.with_saga("compensation", |s| s.compensation = Some(uri))
}
pub fn completion(&mut self, uri: impl Into<String>) -> &mut Self {
let uri = uri.into();
self.with_saga("completion", |s| s.completion = Some(uri))
}
pub fn option(&mut self, name: impl Into<String>, e: impl IntoExpression) -> &mut Self {
let (name, e) = (name.into(), e.into_expression());
self.with_saga("option", |s| s.options.push((name, e)))
}
pub fn saga_service(&mut self, name: impl Into<String>) -> &mut Self {
let name = name.into();
self.with_saga("sagaService", |s| s.saga_service = Some(name))
}
}