use super::report::{catalog_route_pricing, load_session_spend, Valuation};
pub(crate) async fn session_valuation(session_id: &rho_sdk::SessionId) -> Valuation {
if cfg!(test) {
return Valuation::Unpriced;
}
let Ok(path) = crate::paths::usage_database_path() else {
return Valuation::Unpriced;
};
let session_id = session_id.to_string();
let spend = tokio::task::spawn_blocking(move || {
load_session_spend(&path, &session_id, catalog_route_pricing)
})
.await;
match spend {
Ok(Ok(totals)) => totals.valuation(),
Ok(Err(error)) => {
tracing::debug!(%error, "could not read session cost from the usage ledger");
Valuation::Unpriced
}
Err(error) => {
tracing::debug!(%error, "session cost task failed");
Valuation::Unpriced
}
}
}