Skip to main content

assay_workflow/api/
queues.rs

1use std::sync::Arc;
2
3use axum::extract::{Query, State};
4use axum::routing::get;
5use axum::{Json, Router};
6use serde::Deserialize;
7
8use crate::api::workflows::AppError;
9use crate::api::AppState;
10use crate::store::WorkflowStore;
11
12pub fn router<S: WorkflowStore + 'static>() -> Router<Arc<AppState<S>>> {
13    Router::new().route("/queues", get(get_queue_stats))
14}
15
16#[derive(Deserialize)]
17pub struct NsQuery {
18    #[serde(default = "default_namespace")]
19    pub namespace: String,
20}
21
22fn default_namespace() -> String {
23    "main".to_string()
24}
25
26#[utoipa::path(
27    get, path = "/api/v1/queues",
28    tag = "workers",
29    params(("namespace" = Option<String>, Query, description = "Namespace (default: main)")),
30    responses(
31        (status = 200, description = "Queue statistics", body = Vec<QueueStats>),
32    ),
33)]
34pub async fn get_queue_stats<S: WorkflowStore>(
35    State(state): State<Arc<AppState<S>>>,
36    Query(q): Query<NsQuery>,
37) -> Result<Json<Vec<serde_json::Value>>, AppError> {
38    let stats = state.engine.get_queue_stats(&q.namespace).await?;
39    let json: Vec<serde_json::Value> = stats
40        .into_iter()
41        .map(|s| serde_json::to_value(s).unwrap_or_default())
42        .collect();
43    Ok(Json(json))
44}
45
46use crate::store::QueueStats;