feat(chat): make timeouts configurable via environment variables
This commit is contained in:
parent
ed7c4b4402
commit
5ef8b7adcb
3 changed files with 29 additions and 6 deletions
|
|
@ -170,14 +170,30 @@ pub struct SecurityConfig {
|
|||
|
||||
impl Default for DatabaseConfig {
|
||||
fn default() -> Self {
|
||||
let connect_secs = env::var("CHAT_CONNECT_TIMEOUT_SECS")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(5);
|
||||
let acquire_secs = env::var("CHAT_ACQUIRE_TIMEOUT_SECS")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(10);
|
||||
let max_lifetime_secs = env::var("CHAT_MAX_LIFETIME_SECS")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(1800);
|
||||
let idle_secs = env::var("CHAT_IDLE_TIMEOUT_SECS")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(600);
|
||||
Self {
|
||||
database_url: "postgresql://localhost/veza_chat".to_string(),
|
||||
max_connections: 20,
|
||||
min_connections: 5,
|
||||
connect_timeout: Duration::from_secs(5),
|
||||
acquire_timeout: Duration::from_secs(10),
|
||||
max_lifetime: Duration::from_secs(1800), // 30 minutes
|
||||
idle_timeout: Duration::from_secs(600), // 10 minutes
|
||||
connect_timeout: Duration::from_secs(connect_secs),
|
||||
acquire_timeout: Duration::from_secs(acquire_secs),
|
||||
max_lifetime: Duration::from_secs(max_lifetime_secs),
|
||||
idle_timeout: Duration::from_secs(idle_secs),
|
||||
test_before_acquire: true,
|
||||
ssl_mode: SslMode::Prefer,
|
||||
pool_config: PoolConfig::default(),
|
||||
|
|
|
|||
|
|
@ -235,8 +235,14 @@ async fn main() -> Result<(), ChatError> {
|
|||
std::env::var("REDIS_URL").ok().as_deref(),
|
||||
));
|
||||
|
||||
let keepalive_timeout_secs: u64 = std::env::var("CHAT_KEEPALIVE_TIMEOUT_SECS")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(60);
|
||||
|
||||
// État pour le handler WebSocket
|
||||
let ws_state = WebSocketState {
|
||||
keepalive_timeout_secs,
|
||||
message_repo: message_repo.clone(),
|
||||
read_receipt_manager: read_receipt_manager.clone(),
|
||||
delivered_status_manager: delivered_status_manager.clone(),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ use crate::websocket::{IncomingMessage, OutgoingMessage, WebSocketClient, WebSoc
|
|||
/// État partagé pour le handler WebSocket
|
||||
#[derive(Clone)]
|
||||
pub struct WebSocketState {
|
||||
/// Timeout d'inactivité (heartbeat) en secondes, configurable via CHAT_KEEPALIVE_TIMEOUT_SECS
|
||||
pub keepalive_timeout_secs: u64,
|
||||
// pub store: Arc<SimpleMessageStore>, // Remove SimpleMessageStore
|
||||
pub message_repo: Arc<MessageRepository>, // Add MessageRepository
|
||||
pub read_receipt_manager: Arc<ReadReceiptManager>, // Add ReadReceiptManager
|
||||
|
|
@ -156,8 +158,7 @@ async fn handle_socket(
|
|||
return;
|
||||
}
|
||||
|
||||
// Timeout d'inactivité (Heartbeat)
|
||||
let keepalive_timeout = std::time::Duration::from_secs(60);
|
||||
let keepalive_timeout = std::time::Duration::from_secs(state.keepalive_timeout_secs);
|
||||
|
||||
// Boucle principale de gestion des messages avec timeout
|
||||
loop {
|
||||
|
|
|
|||
Loading…
Reference in a new issue