use std::time::Duration;
use crate::{
bson::{oid::ObjectId, Document},
cmap::ConnectionInfo,
error::Error,
};
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct CommandStartedEvent {
pub command: Document,
pub db: String,
pub command_name: String,
pub request_id: i32,
pub connection: ConnectionInfo,
pub service_id: Option<ObjectId>,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct CommandSucceededEvent {
pub duration: Duration,
pub reply: Document,
pub command_name: String,
pub request_id: i32,
pub connection: ConnectionInfo,
pub service_id: Option<ObjectId>,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct CommandFailedEvent {
pub duration: Duration,
pub command_name: String,
pub failure: Error,
pub request_id: i32,
pub connection: ConnectionInfo,
pub service_id: Option<ObjectId>,
}
pub trait CommandEventHandler: Send + Sync {
fn handle_command_started_event(&self, _event: CommandStartedEvent) {}
fn handle_command_succeeded_event(&self, _event: CommandSucceededEvent) {}
fn handle_command_failed_event(&self, _event: CommandFailedEvent) {}
}