apalis_sqlite/queries/
list_queues.rs

1use apalis_core::backend::{BackendExt, ListQueues, QueueInfo};
2use ulid::Ulid;
3
4use crate::{CompactType, SqlContext, SqliteStorage};
5
6struct QueueInfoRow {
7    name: String,
8    stats: String,    // JSON string
9    workers: String,  // JSON string
10    activity: String, // JSON string
11}
12
13impl From<QueueInfoRow> for QueueInfo {
14    fn from(row: QueueInfoRow) -> Self {
15        Self {
16            name: row.name,
17            stats: serde_json::from_str(&row.stats).unwrap(),
18            workers: serde_json::from_str(&row.workers).unwrap(),
19            activity: serde_json::from_str(&row.activity).unwrap(),
20        }
21    }
22}
23
24impl<Args, D, F> ListQueues for SqliteStorage<Args, D, F>
25where
26    Self:
27        BackendExt<Context = SqlContext, Compact = CompactType, IdType = Ulid, Error = sqlx::Error>,
28{
29    fn list_queues(&self) -> impl Future<Output = Result<Vec<QueueInfo>, Self::Error>> + Send {
30        let pool = self.pool.clone();
31
32        async move {
33            let queues = sqlx::query_file_as!(QueueInfoRow, "queries/backend/list_queues.sql")
34                .fetch_all(&pool)
35                .await?
36                .into_iter()
37                .map(QueueInfo::from)
38                .collect();
39            Ok(queues)
40        }
41    }
42}