1use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use std::collections::HashMap;
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
12pub struct QueueMetrics {
13 pub queue_name: String,
15 pub message_count: i64,
17 pub consumer_count: Option<i64>,
19 pub oldest_message_age_seconds: Option<i64>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct ClientStatus {
26 pub client_type: String,
28 pub connected: bool,
30 pub connection_info: HashMap<String, serde_json::Value>,
32 pub last_activity: Option<DateTime<Utc>>,
34}
35
36#[derive(Debug, thiserror::Error)]
38pub enum MessagingError {
39 #[error("Database error: {0}")]
40 Database(#[from] sqlx::Error),
41
42 #[error("Serialization error: {0}")]
43 Serialization(#[from] serde_json::Error),
44
45 #[error("PGMQ error: {0}")]
46 Pgmq(String),
47
48 #[error("Configuration error: {0}")]
49 Configuration(String),
50
51 #[error("Generic error: {0}")]
52 Generic(String),
53}
54
55impl From<String> for MessagingError {
56 fn from(msg: String) -> Self {
57 Self::Generic(msg)
58 }
59}
60
61impl From<&str> for MessagingError {
62 fn from(msg: &str) -> Self {
63 Self::Generic(msg.to_string())
64 }
65}
66
67impl From<anyhow::Error> for MessagingError {
68 fn from(err: anyhow::Error) -> Self {
69 Self::Generic(err.to_string())
70 }
71}
72
73impl From<Box<dyn std::error::Error + Send + Sync>> for MessagingError {
74 fn from(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
75 Self::Generic(err.to_string())
76 }
77}