Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I4a6b498153eccd5407510dd541b7f4816a6a6964
34 lines
982 B
Rust
34 lines
982 B
Rust
use axum::Json;
|
|
use axum::extract::{Path, State};
|
|
|
|
use crate::error::ApiError;
|
|
use crate::state::AppState;
|
|
use pinakes_core::jobs::Job;
|
|
|
|
pub async fn list_jobs(State(state): State<AppState>) -> Json<Vec<Job>> {
|
|
Json(state.job_queue.list().await)
|
|
}
|
|
|
|
pub async fn get_job(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<uuid::Uuid>,
|
|
) -> Result<Json<Job>, ApiError> {
|
|
state.job_queue.status(id).await.map(Json).ok_or_else(|| {
|
|
pinakes_core::error::PinakesError::NotFound(format!("job not found: {id}")).into()
|
|
})
|
|
}
|
|
|
|
pub async fn cancel_job(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<uuid::Uuid>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
let cancelled = state.job_queue.cancel(id).await;
|
|
if cancelled {
|
|
Ok(Json(serde_json::json!({ "cancelled": true })))
|
|
} else {
|
|
Err(pinakes_core::error::PinakesError::NotFound(format!(
|
|
"job not found or already finished: {id}"
|
|
))
|
|
.into())
|
|
}
|
|
}
|