pub fn now_epoch() -> f64 {
chrono::Utc::now().timestamp_millis() as f64 / 1000.0
}
pub fn new_run_id() -> String {
format!(
"{}{}",
uuid::Uuid::new_v4().simple(),
uuid::Uuid::new_v4().simple()
)
}
pub fn new_task_token() -> String {
format!(
"AAAAK{}{}",
uuid::Uuid::new_v4().simple(),
uuid::Uuid::new_v4().simple()
)
}
pub fn domain_arn(region: &str, account: &str, name: &str) -> String {
format!("arn:aws:swf:{region}:{account}:/domain/{name}")
}
pub fn type_key(name: &str, version: &str) -> String {
format!("{name}\u{1}{version}")
}
pub fn split_type_key(key: &str) -> Option<(&str, &str)> {
key.split_once('\u{1}')
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn type_key_round_trips() {
let k = type_key("send-email", "1.0");
assert_eq!(split_type_key(&k), Some(("send-email", "1.0")));
}
#[test]
fn domain_arn_shape() {
assert_eq!(
domain_arn("us-east-1", "000000000000", "orders"),
"arn:aws:swf:us-east-1:000000000000:/domain/orders"
);
}
#[test]
fn run_ids_are_unique_and_shaped() {
let a = new_run_id();
let b = new_run_id();
assert_ne!(a, b);
assert_eq!(a.len(), 64);
assert!(a.chars().all(|c| c.is_ascii_hexdigit()));
}
}