Refactor: Track analysis jobs via InFlight struct

This commit replaces the disk-based `analysis_input.json` marker for
in-progress analysis jobs with an in-memory
`Arc<RwLock<HashSet<PathBuf>>>`.

Previously, the existence of `analysis_input.json` was used as a signal
that a case was queued or being analyzed. This led to stale "Queued"
states after server restarts, as the disk file would persist while the
server process tracking it had vanished.

The new `InFlight` struct, held in `AppState`, provides a process-local
marker. This ensures that:

- Server restarts correctly reset the state, as the `HashSet` is
  cleared.
- Race conditions for triggering analysis are handled by the `try_claim`
  method, replacing the previous reliance on file system `O_EXCL` flags.
- The `AnalyzeJob` payload now travels with the job over the channel,
  eliminating the need for workers to re-read `analysis_input.json` from
  disk.

This change simplifies state management and improves the reliability of
analysis job tracking.
This commit is contained in:
2026-05-05 20:01:07 +02:00
parent e0cfd5d512
commit 76bf65be1a
15 changed files with 704 additions and 336 deletions
+3 -8
View File
@@ -14,9 +14,9 @@ use doctate_common::oneliners::OnelinerState;
use tower::util::ServiceExt;
use common::{
ANALYSIS_INPUT_FILE, DOCUMENT_FILE, ONELINER_FILENAME, TestConfig, csrf_form_post,
login_with_csrf, paths, seed_case, seed_oneliner_ready, seed_oneliner_state,
seed_recording_with_sidecars, test_user, write_document_for_test,
DOCUMENT_FILE, ONELINER_FILENAME, TestConfig, csrf_form_post, login_with_csrf, paths,
seed_case, seed_oneliner_ready, seed_oneliner_state, seed_recording_with_sidecars, test_user,
write_document_for_test,
};
fn delete_body(filename: &str) -> String {
@@ -38,7 +38,6 @@ async fn delete_recording_removes_file_and_sidecars_and_invalidates_derived() {
// delete — keeps the original contract „auto state must be wiped".
seed_oneliner_ready(&case_dir, "knee, left, pain");
write_document_for_test(&case_dir, "# stale", "1970-01-01T00:00:00Z");
std::fs::write(case_dir.join(ANALYSIS_INPUT_FILE), b"{}").unwrap();
let (app, store) = doctate_server::create_router_and_session_store(cfg);
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
@@ -91,10 +90,6 @@ async fn delete_recording_removes_file_and_sidecars_and_invalidates_derived() {
!case_dir.join(DOCUMENT_FILE).exists(),
"document.md must be cleared"
);
assert!(
!case_dir.join(ANALYSIS_INPUT_FILE).exists(),
"analysis_input.json must be cleared"
);
}
#[tokio::test]