pub enum TriggerCondition {
Label {
key: String,
value: String,
},
Expression(Arc<dyn Fn(&TriggerContext) -> bool + Send + Sync>),
}Expand description
A condition that must be satisfied for an EventTriggerRule to fire.
All conditions on a rule are evaluated with AND semantics: the rule
fires only when every condition returns true. For OR semantics,
create separate rules.
§Examples
use ironflow_runtime::trigger::event::TriggerCondition;
let cond = TriggerCondition::Label {
key: "env".to_string(),
value: "prod".to_string(),
};
assert!(matches!(cond, TriggerCondition::Label { .. }));Variants§
Label
The source run must carry a label with this exact key-value pair.
Expression(Arc<dyn Fn(&TriggerContext) -> bool + Send + Sync>)
An arbitrary predicate evaluated against the TriggerContext.
Uses Arc so the condition is Clone + Send + Sync.
Implementations§
Source§impl TriggerCondition
impl TriggerCondition
Sourcepub fn evaluate(&self, ctx: &TriggerContext) -> bool
pub fn evaluate(&self, ctx: &TriggerContext) -> bool
Evaluate this condition against the given context.
§Examples
use std::collections::HashMap;
use ironflow_runtime::trigger::event::{TriggerCondition, TriggerContext};
use rust_decimal::Decimal;
let ctx = TriggerContext {
labels: HashMap::from([("env".to_string(), "prod".to_string())]),
error: None,
cost_usd: Decimal::ZERO,
duration_ms: 0,
};
let cond = TriggerCondition::Label {
key: "env".to_string(),
value: "prod".to_string(),
};
assert!(cond.evaluate(&ctx));§Panics
Does not panic. If an Expression
closure panics, the panic is caught and the condition evaluates to
false.
Trait Implementations§
Source§impl Clone for TriggerCondition
impl Clone for TriggerCondition
Auto Trait Implementations§
impl !RefUnwindSafe for TriggerCondition
impl !UnwindSafe for TriggerCondition
impl Freeze for TriggerCondition
impl Send for TriggerCondition
impl Sync for TriggerCondition
impl Unpin for TriggerCondition
impl UnsafeUnpin for TriggerCondition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more