feat: init
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::service::ServiceContext;
|
||||
use delivery_trace::{trace_error, trace_request};
|
||||
use events::ImEvent;
|
||||
|
||||
pub mod articles;
|
||||
pub mod categories;
|
||||
pub mod channels;
|
||||
pub mod delivery_trace;
|
||||
pub mod drafts;
|
||||
pub mod events;
|
||||
pub mod follows;
|
||||
pub mod members;
|
||||
pub mod messages;
|
||||
pub mod polls;
|
||||
pub mod presence;
|
||||
pub mod reactions;
|
||||
pub mod session;
|
||||
pub mod threads;
|
||||
pub mod util;
|
||||
|
||||
pub use messages::{EditMessageParams, SendMessageParams};
|
||||
pub use presence::UpdatePresenceParams;
|
||||
pub use session::ImSession;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
impl ImService {
|
||||
fn emit_event(&self, event: ImEvent) {
|
||||
let _ = self.ctx.im_events.publish(event);
|
||||
}
|
||||
|
||||
async fn publish<T: Serialize>(&self, subject: &str, request_id: Uuid, event: &T) {
|
||||
match self
|
||||
.ctx
|
||||
.nats
|
||||
.publish_with_headers(
|
||||
subject,
|
||||
&serde_json::to_vec(event).unwrap_or_default(),
|
||||
vec![("X-Request-Id".into(), request_id.to_string())],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => trace_request("nats_published", request_id, subject),
|
||||
Err(e) => {
|
||||
trace_error("nats_failed", request_id, subject, &e);
|
||||
tracing::warn!(subject, error = %e, "nats publish failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user