MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / _process_job

Method _process_job

codewiki/src/fe/background_worker.py:163–256  ·  view source on GitHub ↗

Process a single documentation generation job.

(self, job_id: str)

Source from the content-addressed store, hash-verified

161 time.sleep(1)
162
163 def _process_job(self, job_id: str):
164 """Process a single documentation generation job."""
165 if job_id not in self.job_status:
166 return
167
168 job = self.job_status[job_id]
169
170 try:
171 # Update job status
172 job.status = 'processing'
173 job.started_at = datetime.now()
174 job.progress = "Starting repository clone..."
175 job.main_model = MAIN_MODEL
176
177 # Check cache first
178 cached_docs = self.cache_manager.get_cached_docs(job.repo_url)
179 if cached_docs and Path(cached_docs).exists():
180 job.status = 'completed'
181 job.completed_at = datetime.now()
182 job.docs_path = cached_docs
183 job.progress = "Documentation retrieved from cache"
184 if not job.main_model: # Only set if not already set
185 job.main_model = MAIN_MODEL
186
187 # Save job status to disk
188 self.save_job_statuses()
189
190 print(f"Job {job_id}: Using cached documentation")
191 return
192
193 # Clone repository
194 repo_info = GitHubRepoProcessor.get_repo_info(job.repo_url)
195 # Use repo full name for temp directory (already URL-safe since job_id is URL-safe)
196 temp_repo_dir = os.path.join(self.temp_dir, job_id)
197
198 job.progress = f"Cloning repository {repo_info['full_name']}..."
199
200 if not GitHubRepoProcessor.clone_repository(repo_info['clone_url'], temp_repo_dir, job.commit_id):
201 raise Exception("Failed to clone repository")
202
203 # Generate documentation
204 job.progress = "Analyzing repository structure..."
205
206 # Create config for documentation generation (using env vars)
207 import argparse
208 args = argparse.Namespace(repo_path=temp_repo_dir)
209 config = Config.from_args(args)
210 # Override docs_dir with job-specific directory
211 config.docs_dir = os.path.join("output", "docs", f"{job_id}-docs")
212
213 job.progress = "Generating documentation..."
214
215 # Generate documentation
216 doc_generator = DocumentationGenerator(config, job.commit_id)
217
218 # Run the async documentation generation in a new event loop
219 loop = asyncio.new_event_loop()
220 asyncio.set_event_loop(loop)

Callers 1

_worker_loopMethod · 0.95

Calls 8

save_job_statusesMethod · 0.95
runMethod · 0.95
get_cached_docsMethod · 0.80
get_repo_infoMethod · 0.80
clone_repositoryMethod · 0.80
from_argsMethod · 0.80
add_to_cacheMethod · 0.80

Tested by

no test coverage detected