use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AlignRequest { pub audio_base64: String, pub text: String, #[serde(default = "default_language")] pub language: String, #[serde(default = "default_pass_number")] pub pass_number: i32, pub client_id: Option, } fn default_language() -> String { "english".to_string() } fn default_pass_number() -> i32 { 1 } #[derive(Debug, Deserialize)] pub struct CancelRequest { pub client_id: Option, } #[derive(Debug, Deserialize)] pub struct JobQuery { pub slim: Option, } #[derive(Debug, Clone, PartialEq)] pub enum JobStatus { Queued, Running, Completed, Failed, Abandoned, } impl JobStatus { pub fn as_str(&self) -> &'static str { match self { JobStatus::Queued => "queued", JobStatus::Running => "running", JobStatus::Completed => "completed", JobStatus::Failed => "failed", JobStatus::Abandoned => "abandoned", } } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct WordTimestamp { pub word: String, pub start: f64, pub end: f64, } #[derive(Debug, Clone)] pub struct Job { pub id: String, pub request: AlignRequest, pub status: JobStatus, pub created_at: DateTime, pub started_at: Option>, pub terminal_at: Option>, pub result: Option>, pub error: Option, pub client_id: Option, pub audio_duration: f64, pub wav_path: String, pub cleaned_text: String, } #[derive(Debug, Default)] pub struct Metrics { pub total_submitted: i32, pub total_completed: i32, pub total_failed: i32, pub total_abandoned: i32, pub total_cancelled: i32, pub start_time: Option>, } impl Metrics { pub fn new() -> Self { Self { start_time: Some(Utc::now()), ..Default::default() } } }