Refactor busy flags and worker guards

The `WorkerBusy` type was previously a single `Arc<AtomicBool>` shared
between the analyze and transcribe workers. This commit refactors this
to:

- Introduce `AnalyzeBusy` and `TranscribeBusy` newtype wrappers around
  `WorkerBusy` to distinguish between the two flags. This allows
  `axum::extract::State` to target them individually.
- Move the `BusyGuard` RAII guard into `src/lib.rs` and make it generic
  to work with any `WorkerBusy` instance.
- Update the `main.rs`, `worker.rs`, and `routes/user_web.rs` files to
  use the new types and guards, ensuring correct state management for
  both pipelines.
- Enhance the transcription recovery scan
  (`transcribe::recovery::scan_and_enqueue`) to iterate over user
  directories and call `enqueue_pending_for_user` for each, making it
  more robust and aligned with the per-user self-healing mechanism.
- Add a check for `transcribe_busy` in the `case_detail.html` template
  to correctly display "Transkription läuft…" only when the transcribe
  worker is actually active.
This commit is contained in:
2026-04-16 00:32:45 +02:00
parent 9072d7a833
commit 2f62f11563
8 changed files with 175 additions and 118 deletions
+7 -3
View File
@@ -66,10 +66,13 @@ async fn main() {
// Transcription pipeline: channel + worker + recovery scan.
let (transcribe_tx, transcribe_rx) = transcribe::channel();
let transcribe_busy: doctate_server::WorkerBusy =
std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
tokio::spawn(transcribe::worker::run(
transcribe_rx,
config.clone(),
http_client.clone(),
transcribe_busy.clone(),
));
{
let tx = transcribe_tx.clone();
@@ -81,13 +84,13 @@ async fn main() {
// Analyze pipeline: channel + worker + recovery scan.
let (analyze_tx, analyze_rx) = analyze::channel();
let worker_busy: doctate_server::WorkerBusy =
let analyze_busy: doctate_server::WorkerBusy =
std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
tokio::spawn(analyze::worker::run(
analyze_rx,
config.clone(),
http_client.clone(),
worker_busy.clone(),
analyze_busy.clone(),
));
{
let tx = analyze_tx.clone();
@@ -102,7 +105,8 @@ async fn main() {
transcribe_tx,
analyze_tx,
session_store: doctate_server::web_session::new_store(),
worker_busy,
analyze_busy: doctate_server::AnalyzeBusy(analyze_busy),
transcribe_busy: doctate_server::TranscribeBusy(transcribe_busy),
};
let addr = format!("0.0.0.0:{}", config.server_port);