apalis_sqlite/queries/
list_queues.rs

1use apalis_core::backend::{BackendExt, ListQueues, QueueInfo};
2use ulid::Ulid;
3
4use crate::{CompactType, SqliteContext, 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: BackendExt<
27            Context = SqliteContext,
28            Compact = CompactType,
29            IdType = Ulid,
30            Error = sqlx::Error,
31        >,
32{
33    fn list_queues(&self) -> impl Future<Output = Result<Vec<QueueInfo>, Self::Error>> + Send {
34        let pool = self.pool.clone();
35
36        async move {
37            let queues = sqlx::query_file_as!(QueueInfoRow, "queries/backend/list_queues.sql")
38                .fetch_all(&pool)
39                .await?
40                .into_iter()
41                .map(QueueInfo::from)
42                .collect();
43            Ok(queues)
44        }
45    }
46}