Skip to main content

boson_backend_sqlite/
bootstrap.rs

1//! Bootstrap helper — register `SQLite` backend on the global [`QueueRouter`](boson_core::QueueRouter).
2
3use std::path::Path;
4use std::sync::Arc;
5
6use boson_core::{QueueBackend, QueueRouter};
7
8use crate::SqliteQueueBackend;
9
10/// Install a new [`SqliteQueueBackend`] as the process-global default backend.
11///
12/// # Errors
13///
14/// Propagates errors from [`SqliteQueueBackend::new`].
15pub async fn install_default_sqlite_backend(
16    path: impl AsRef<Path>,
17) -> boson_core::Result<Arc<SqliteQueueBackend>> {
18    let backend = Arc::new(SqliteQueueBackend::new(path).await?);
19    let dyn_backend: Arc<dyn QueueBackend> = Arc::clone(&backend) as Arc<dyn QueueBackend>;
20    QueueRouter::set_global(QueueRouter::with_default(dyn_backend));
21    Ok(backend)
22}