refactor: update channel bus and thread event
This commit is contained in:
parent
d0155c66d2
commit
25b73e1054
@ -421,19 +421,15 @@ impl ChannelBus {
|
||||
async fn publish_event(&self, event: ChannelEvent) -> ChannelResult<()> {
|
||||
self.inner.metrics.increment_sent();
|
||||
|
||||
// Best-effort broadcast — individual socket failures are expected
|
||||
// (sockets disconnect) and should not block all broadcasts.
|
||||
let result = self
|
||||
.inner
|
||||
.circuit_breaker
|
||||
.call(async {
|
||||
self.inner
|
||||
.io
|
||||
.namespace(&self.inner.config.namespace)
|
||||
.await
|
||||
.to(room_socket_name(event.room))
|
||||
.emit(ROOM_MESSAGE_EVENT, event)
|
||||
.await
|
||||
.map_err(ChannelError::SocketIo)
|
||||
})
|
||||
.io
|
||||
.namespace(&self.inner.config.namespace)
|
||||
.await
|
||||
.to(room_socket_name(event.room))
|
||||
.emit(ROOM_MESSAGE_EVENT, event)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
@ -442,17 +438,9 @@ impl ChannelBus {
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "WS broadcast failed");
|
||||
self.inner.metrics.increment_failed();
|
||||
match e {
|
||||
crate::circuit_breaker::CircuitBreakerError::Open => {
|
||||
Err(ChannelError::Internal(
|
||||
"circuit breaker open".to_string(),
|
||||
))
|
||||
}
|
||||
crate::circuit_breaker::CircuitBreakerError::Inner(e) => {
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
Ok(()) // best-effort: don't propagate broadcast errors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,3 +103,24 @@ pub struct ThreadArchiveClient {
|
||||
pub struct ThreadLoadClient {
|
||||
pub thread_id: Uuid,
|
||||
}
|
||||
|
||||
/// A single thread item returned in the list endpoint
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ThreadListItem {
|
||||
pub id: Uuid,
|
||||
pub room: RoomInfo,
|
||||
pub seq: i64,
|
||||
pub parent_seq: i64,
|
||||
pub title: String,
|
||||
pub created_by: UserInfo,
|
||||
pub archived: bool,
|
||||
pub locked: bool,
|
||||
pub last_message_at: Option<DateTime<Utc>>,
|
||||
pub last_message_preview: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ThreadListService {
|
||||
pub threads: Vec<ThreadListItem>,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user