Skip to main content

af_workflow/
ingress.rs

1//! Pure ingress planning helpers for durable workflow hosts.
2
3use chrono::{DateTime, Utc};
4
5use crate::{NodeRegistry, Spec};
6
7pub fn next_cron_at(expression: &str, after: DateTime<Utc>) -> Result<DateTime<Utc>, String> {
8    expression
9        .parse::<cron::Schedule>()
10        .map_err(|error| format!("invalid cron '{expression}': {error}"))?
11        .after(&after)
12        .next()
13        .ok_or_else(|| format!("cron '{expression}' has no future occurrence"))
14}
15
16#[derive(Debug, Clone, PartialEq)]
17pub struct BranchIngressPlan {
18    pub branch_id: String,
19    pub ingress_type: String,
20    pub ingress_config: serde_json::Value,
21}
22
23pub fn ingress_plans(spec: &Spec, registry: &NodeRegistry) -> Vec<BranchIngressPlan> {
24    spec.branches
25        .iter()
26        .filter_map(|branch| {
27            let ingress = branch
28                .nodes
29                .iter()
30                .find(|node| registry.is_ingress(&node.node_type))?;
31            Some(BranchIngressPlan {
32                branch_id: branch.branch_id.clone(),
33                ingress_type: ingress.node_type.clone(),
34                ingress_config: ingress.config.clone(),
35            })
36        })
37        .collect()
38}