Skip to main content

aurelin_framework/
queue.rs

1//! Durable background jobs backed by SQLite and Apalis.
2
3use apalis_sqlite::{SqlitePool, SqliteStorage};
4
5pub use apalis::prelude::{BoxDynError, TaskSink, WorkerBuilder, WorkerContext};
6
7/// Connect to a SQLite queue and create its storage schema when necessary.
8pub async fn sqlite<J>(database_url: &str) -> Result<SqliteStorage<J>, Error> {
9    let pool = SqlitePool::connect(database_url).await?;
10    SqliteStorage::setup(&pool).await?;
11    Ok(SqliteStorage::new(&pool))
12}
13
14/// Failures encountered while opening or preparing a SQLite queue.
15#[derive(Debug, thiserror::Error)]
16pub enum Error {
17    /// The SQLite connection could not be opened.
18    #[error("connect to the queue database: {0}")]
19    Connect(#[from] apalis_sqlite::SqlxError),
20    /// The queue schema could not be prepared.
21    #[error("prepare the queue database: {0}")]
22    Setup(#[from] apalis_sqlite::Error),
23}