refactor(server): bundle worker pipeline into PipelineState
Group the four worker handles (analyze/transcribe x busy/tx) into a new PipelineState struct with a FromRef<AppState> impl. Convert heal_orphans_if_idle from a free function with 6 parameters into a method on PipelineState. The two web handlers (handle_my_cases, handle_case_detail) now take one State<PipelineState> instead of four separate State extractors. The original FromRef impls for AnalyzeBusy/Sender and TranscribeBusy/ Sender remain intact so handlers that need only one of them keep their narrower signature.
This commit is contained in:
@@ -51,6 +51,20 @@ impl Drop for BusyGuard {
|
||||
}
|
||||
}
|
||||
|
||||
/// Bundle of the four worker-pipeline handles (analyze + transcribe,
|
||||
/// each with a busy-flag and a job sender). Extracted so handlers that
|
||||
/// need the whole pipeline (self-heal, status probes) can take a single
|
||||
/// `State<PipelineState>` instead of four separate `State(...)` params.
|
||||
/// The individual `FromRef<AppState>` impls below remain valid, so
|
||||
/// handlers that only need one sender keep their narrower signature.
|
||||
#[derive(Clone)]
|
||||
pub struct PipelineState {
|
||||
pub analyze_busy: AnalyzeBusy,
|
||||
pub analyze_tx: AnalyzeSender,
|
||||
pub transcribe_busy: TranscribeBusy,
|
||||
pub transcribe_tx: TranscribeSender,
|
||||
}
|
||||
|
||||
/// Shared application state. Clonable — all fields are cheap to clone
|
||||
/// (`Arc` and `mpsc::Sender`).
|
||||
#[derive(Clone)]
|
||||
@@ -99,6 +113,17 @@ impl FromRef<AppState> for TranscribeBusy {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for PipelineState {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
PipelineState {
|
||||
analyze_busy: state.analyze_busy.clone(),
|
||||
analyze_tx: state.analyze_tx.clone(),
|
||||
transcribe_busy: state.transcribe_busy.clone(),
|
||||
transcribe_tx: state.transcribe_tx.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Test/simple entrypoint: jobs pushed into either channel are dropped
|
||||
/// because the receivers are not retained. Use [`create_router_with_state`]
|
||||
/// from `main.rs` where real workers own the receivers.
|
||||
|
||||
Reference in New Issue
Block a user