1use vlo_types::{DeriveIdsInput, DeriveIdsOutput};
6
7use crate::hash::sha256_hex;
8
9const CHILD_RUN_ID_HEX_LEN: usize = 26;
11
12pub fn task_id(run_id: &str, step_id: &str) -> String {
14 format!("{run_id}:{step_id}")
15}
16
17pub fn idempotency_key(run_id: &str, step_id: &str, attempt: u32) -> String {
19 format!("{run_id}:{step_id}:{attempt}")
20}
21
22pub fn child_run_id(run_id: &str, step_id: &str) -> String {
24 let digest = sha256_hex(task_id(run_id, step_id).as_bytes());
25 format!("run_{}", &digest[..CHILD_RUN_ID_HEX_LEN])
26}
27
28pub fn derive_ids(input: &DeriveIdsInput) -> DeriveIdsOutput {
30 DeriveIdsOutput {
31 task_id: task_id(&input.run_id, &input.step_id),
32 idempotency_key: idempotency_key(&input.run_id, &input.step_id, input.attempt),
33 child_run_id: child_run_id(&input.run_id, &input.step_id),
34 }
35}