relay_knowledge/application/code_repository/indexing/
mod.rs1mod business_projection;
4mod durable_incremental;
5mod fast_path;
6mod preview;
7mod queue;
8mod session;
9mod start;
10mod state;
11mod task;
12mod tasks;
13mod worker;
14mod workflow;
15
16use crate::{
17 api::{ApiError, CodeRepositoryIndexResponse, RequestContext},
18 application::service::RelayKnowledgeService,
19 domain::CodeIndexRequest,
20};
21
22use self::task::CodeIndexTaskLeaseContext;
23
24pub(super) use task::recover_code_index_task_leases;
25
26impl RelayKnowledgeService {
27 pub async fn index_code_repository(
29 &self,
30 request: CodeIndexRequest,
31 context: RequestContext,
32 ) -> Result<CodeRepositoryIndexResponse, ApiError> {
33 let started = self
34 .start_code_repository_index(request, context.clone())
35 .await?;
36 if let Some(summary) = started.summary {
37 return Ok(CodeRepositoryIndexResponse {
38 metadata: started.metadata,
39 scope: started.scope,
40 summary,
41 status: started.status,
42 });
43 }
44 let task_id = started
45 .task
46 .as_ref()
47 .map(|task| task.task_id.clone())
48 .ok_or_else(|| {
49 ApiError::storage_unavailable("durable repository index did not return a task")
50 })?;
51 self.run_code_index_task_once_with_response(Some(task_id.clone()), context)
52 .await?
53 .map(|(_, response)| response)
54 .ok_or_else(|| {
55 ApiError::qos_rejected(format!(
56 "durable repository index task '{task_id}' is already claimed or queued behind another repository writer; inspect repo status and let the managed worker drain it"
57 ))
58 })
59 }
60
61 async fn index_code_repository_inner(
62 &self,
63 request: CodeIndexRequest,
64 context: RequestContext,
65 task_lease: Option<CodeIndexTaskLeaseContext>,
66 ) -> Result<CodeRepositoryIndexResponse, ApiError> {
67 workflow::run(self, request, context, task_lease).await
68 }
69}
70
71#[cfg(test)]
72use self::{
73 durable_incremental::{checkpoint_skips_parser, should_resume_staged_full},
74 workflow::publication::incremental_snapshot_matches_lease,
75};
76
77#[cfg(test)]
78#[path = "resume_tests.rs"]
79mod resume_tests;