use std::collections::HashMap;
use super::super::command::slugify;
use super::super::model::RoutineStore;
use super::runtime::MAX_RUNTIME_SECS;
use super::ttl::MAX_TTL_SECS;
pub fn snapshot_ttls(store: &RoutineStore) -> HashMap<String, u64> {
let lock = store.lock().unwrap();
lock.values()
.map(|routine| (slugify(&routine.title), routine.effective_ttl_secs()))
.collect()
}
pub fn ttl_for(snapshot: &HashMap<String, u64>, slug: &str) -> u64 {
snapshot.get(slug).copied().unwrap_or(MAX_TTL_SECS)
}
pub fn snapshot_max_runtimes(store: &RoutineStore) -> HashMap<String, u64> {
let lock = store.lock().unwrap();
lock.values()
.map(|routine| {
(
slugify(&routine.title),
routine.effective_max_runtime_secs(),
)
})
.collect()
}
pub fn max_runtime_for(snapshot: &HashMap<String, u64>, slug: &str) -> u64 {
snapshot.get(slug).copied().unwrap_or(MAX_RUNTIME_SECS)
}
#[cfg(test)]
#[path = "snapshot_tests.rs"]
mod snapshot_tests;