assay_workflow/api/
workers.rs1use 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()
14 .route("/workers", get(list_workers))
15 .route("/health", get(health_check))
16}
17
18#[derive(Deserialize)]
19pub struct NsQuery {
20 #[serde(default = "default_namespace")]
21 namespace: String,
22}
23
24fn default_namespace() -> String {
25 "main".to_string()
26}
27
28#[utoipa::path(
29 get, path = "/api/v1/workers",
30 tag = "workers",
31 params(("namespace" = Option<String>, Query, description = "Namespace (default: main)")),
32 responses(
33 (status = 200, description = "List of active workers", body = Vec<WorkflowWorker>),
34 ),
35)]
36pub async fn list_workers<S: WorkflowStore>(
37 State(state): State<Arc<AppState<S>>>,
38 Query(q): Query<NsQuery>,
39) -> Result<Json<Vec<serde_json::Value>>, AppError> {
40 let workers = state.engine.list_workers(&q.namespace).await?;
41 let json: Vec<serde_json::Value> = workers
42 .into_iter()
43 .map(|w| serde_json::to_value(w).unwrap_or_default())
44 .collect();
45 Ok(Json(json))
46}
47
48#[utoipa::path(
49 get, path = "/api/v1/health",
50 tag = "workers",
51 responses(
52 (status = 200, description = "Engine health status"),
53 ),
54)]
55pub async fn health_check() -> Json<serde_json::Value> {
56 Json(serde_json::json!({
57 "status": "ok",
58 "service": "assay-workflow",
59 }))
60}
61
62use crate::types::WorkflowWorker;