use ci_protocol::events::CiEvent; use export::AppRedis; use git::sync::queue::SyncQueue; use crate::errors::{CiError, CiResult}; #[must_use] pub fn event_queue(redis: AppRedis) -> SyncQueue { SyncQueue::new(redis) } pub async fn publish_event(redis: &AppRedis, topic: &str, event: &CiEvent) -> CiResult<()> { let payload = serde_json::to_vec(event)?; let queue = SyncQueue::new(redis.clone()); queue .publish_raw(topic, None, &payload) .await .map_err(|e| CiError::Internal(format!("event publish failed: {e}")))?; tracing::debug!(topic, bytes = payload.len(), "ci event published"); Ok(()) } pub async fn publish_event_to_dlq(redis: &AppRedis, topic: &str, payload: &[u8]) -> CiResult<()> { let queue = SyncQueue::new(redis.clone()); queue .publish_raw(topic, None, payload) .await .map_err(|e| CiError::Internal(format!("event dlq publish failed: {e}")))?; Ok(()) } pub fn decode_event(payload: &[u8]) -> CiResult { serde_json::from_slice(payload) .map_err(|e| CiError::Internal(format!("malformed ci event: {e}"))) }