Skip to main content

linkrs_query/
session_events.rs

1use std::sync::Arc;
2
3/// Session and query lifecycle notification.
4///
5/// `SessionCreated` / `SessionDestroyed` are emitted by the server-side
6/// session manager, while `QueryStarted` / `QueryCompleted` /
7/// `SlowQueryDetected` are emitted by `QueryManager`. A single enum is used
8/// so observers can subscribe once and receive both halves.
9/// The event reference is valid only for the dispatch call; observers must
10/// not retain it beyond the callback.
11#[derive(Debug, Clone)]
12pub enum SessionEvent {
13    SessionCreated {
14        session_id: i64,
15        user_name: String,
16    },
17    SessionDestroyed {
18        session_id: i64,
19    },
20    QueryStarted {
21        session_id: i64,
22        query_id: i64,
23        query_text: String,
24    },
25    QueryCompleted {
26        session_id: i64,
27        query_id: i64,
28        duration_ms: i64,
29        success: bool,
30    },
31    SlowQueryDetected {
32        session_id: i64,
33        query_id: i64,
34        duration_ms: i64,
35        threshold_ms: i64,
36    },
37}
38
39/// Runtime observer for session/query events.
40pub type SessionEventCallback = Arc<dyn Fn(&SessionEvent) + Send + Sync>;