headless_lms_server/domain/internal_error_reporting.rs
1use std::sync::OnceLock;
2
3use sqlx::PgPool;
4
5static ERROR_REPORTING_POOL: OnceLock<PgPool> = OnceLock::new();
6
7/// Initializes the shared internal error-reporting pool once.
8/// Subsequent calls are ignored and logged as warnings.
9pub fn init_error_reporting(pool: PgPool) {
10 if ERROR_REPORTING_POOL.set(pool).is_err() {
11 tracing::warn!("init_error_reporting called more than once; keeping existing pool");
12 }
13}
14
15/// Returns the globally initialized internal error-reporting pool, if set.
16pub fn error_reporting_pool() -> Option<&'static PgPool> {
17 ERROR_REPORTING_POOL.get()
18}