Built for people who think better out loud.
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

at icorbrey/netlify 44 lines 1.1 kB view raw
1use chrono::Utc; 2 3/// Aggregated usage for a feature within a billing period. 4#[derive(Debug, Clone)] 5pub struct UsageSummary { 6 pub limit_seconds: Option<f64>, 7 pub used_seconds: f64, 8 #[allow(dead_code)] 9 pub period: UsagePeriod, 10} 11 12/// Decision for whether the user may consume more of a feature. 13#[derive(Debug, Clone)] 14pub enum UsageDecision { 15 Allowed, 16 Exceeded { limit_seconds: f64, used_seconds: f64 }, 17} 18 19impl UsageSummary { 20 /// Evaluates the usage against the limit, if any. 21 pub fn decision(&self) -> UsageDecision { 22 match self.limit_seconds { 23 Some(limit) if self.used_seconds >= limit => UsageDecision::Exceeded { 24 limit_seconds: limit, 25 used_seconds: self.used_seconds, 26 }, 27 _ => UsageDecision::Allowed, 28 } 29 } 30} 31 32/// Billing period boundaries for usage aggregation. 33#[derive(Debug, Clone)] 34pub struct UsagePeriod { 35 pub start: chrono::DateTime<Utc>, 36 pub end: chrono::DateTime<Utc>, 37} 38 39impl UsagePeriod { 40 /// Returns the label used in API responses. 41 pub fn label(&self) -> &'static str { 42 "month" 43 } 44}