use aion_core::{WorkflowId, WorkloopSpecError};
pub use aion_core::hatch_workflow_id as hatch_identity;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum HatchOutcome {
Hatched(WorkflowId),
Existing(WorkflowId),
}
impl HatchOutcome {
#[must_use]
pub const fn workflow_id(&self) -> &WorkflowId {
match self {
Self::Hatched(id) | Self::Existing(id) => id,
}
}
}
pub fn derive_identity(
namespace: &str,
workflow_type: &str,
key: &str,
) -> Result<WorkflowId, WorkloopSpecError> {
hatch_identity(namespace, workflow_type, key)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn outcome_exposes_the_resolved_id_both_ways() -> Result<(), Box<dyn std::error::Error>> {
let id = derive_identity("default", "process_task", "task-1")?;
assert_eq!(HatchOutcome::Hatched(id.clone()).workflow_id(), &id);
assert_eq!(HatchOutcome::Existing(id.clone()).workflow_id(), &id);
Ok(())
}
}