44c320d8fa
Track required workspace crates, scripts, and historical diesel migrations so the repository contains the complete runnable backend baseline. Made-with: Cursor
39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
use std::sync::Arc;
|
|
|
|
use axum::extract::State;
|
|
use axum::Json;
|
|
use htycommons::common::HtyResponse;
|
|
use htycommons::web::wrap_ok_resp;
|
|
|
|
use crate::processor::{ProcMachineStatus, ProcessorRuntime};
|
|
|
|
pub async fn proc_start(State(rt): State<Arc<ProcessorRuntime>>) -> Json<HtyResponse<String>> {
|
|
let should_spawn = {
|
|
let mut st = rt.machine_status.lock().expect("proc status mutex poisoned");
|
|
if *st == ProcMachineStatus::Running {
|
|
tracing::warn!("TASK PROCESSOR ALREADY STARTED");
|
|
false
|
|
} else {
|
|
*st = ProcMachineStatus::Running;
|
|
true
|
|
}
|
|
};
|
|
if should_spawn {
|
|
let r = rt.clone();
|
|
tokio::spawn(crate::processor::processor_loop(r));
|
|
}
|
|
Json(wrap_ok_resp(ProcMachineStatus::Running.as_java_str().to_string()))
|
|
}
|
|
|
|
pub async fn proc_stop(State(rt): State<Arc<ProcessorRuntime>>) -> Json<HtyResponse<String>> {
|
|
*rt.machine_status.lock().expect("proc status mutex poisoned") = ProcMachineStatus::Abort;
|
|
Json(wrap_ok_resp(ProcMachineStatus::Abort.as_java_str().to_string()))
|
|
}
|
|
|
|
/// `d` is a plain string (`RUNNING` / `PENDING` / …) so `htyadmin` `TaskProcessorStatus` matches Java `wrapOkResponse(Status)`.
|
|
pub async fn proc_status(State(rt): State<Arc<ProcessorRuntime>>) -> Json<HtyResponse<String>> {
|
|
Json(wrap_ok_resp(
|
|
rt.proc_status().as_java_str().to_string(),
|
|
))
|
|
}
|