Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions codewiki/src/fe/background_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import threading
import subprocess
import asyncio
import logging
from datetime import datetime
from pathlib import Path
from queue import Queue
Expand All @@ -23,6 +24,8 @@
from .config import WebAppConfig
from codewiki.src.utils import file_manager

logger = logging.getLogger(__name__)

class BackgroundWorker:
"""Background worker for processing documentation generation jobs."""

Expand All @@ -41,7 +44,7 @@ def start(self):
self.running = True
thread = threading.Thread(target=self._worker_loop, daemon=True)
thread.start()
print("Background worker started")
logger.info("Background worker started")

def stop(self):
"""Stop the background worker."""
Comment on lines 44 to 50

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 print() used instead of module logger in background_worker.py

Added import logging and a module-level logger = logging.getLogger(__name__) near the top of codewiki/src/fe/background_worker.py, then replaced every print(...) call across the file (in start, load_job_statuses, _reconstruct_jobs_from_cache, save_job_statuses, _worker_loop, and _process_job) with the equivalent logger.info(...) or logger.error(...) call depending on whether the original message indicated a normal status update or an error/failure condition. No behavior, formatting, or control flow was otherwise changed.

πŸ€– Prompt for AI agents
In codewiki/src/fe/background_worker.py around line 39, review and complete this code-review fix: print() used instead of module logger in background_worker.py.
What the draft fix changed: Added `import logging` and a module-level `logger = logging.getLogger(__name__)` near the top of `codewiki/src/fe/background_worker.py`, then replaced every `print(...)` call across the file (in `start`, `load_job_statuses`, `_reconstruct_jobs_from_cache`, `save_job_statuses`, `_worker_loop`, and `_process_job`) with the equivalent `logger.info(...)` or `logger.error(...)` call depending on whether the original message indicated a normal status update or an error/failure condition. No behavior, formatting, or control flow was otherwise changed.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 90 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Expand Down Expand Up @@ -84,9 +87,9 @@ def load_job_statuses(self):
progress=job_data.get('progress', ''),
docs_path=job_data.get('docs_path')
)
print(f"Loaded {len([j for j in self.job_status.values() if j.status == 'completed'])} completed jobs from disk")
logger.info(f"Loaded {len([j for j in self.job_status.values() if j.status == 'completed'])} completed jobs from disk")
except Exception as e:
print(f"Error loading job statuses: {e}")
logger.error(f"Error loading job statuses: {e}")

def _reconstruct_jobs_from_cache(self):
"""Reconstruct job statuses from cache entries for backward compatibility."""
Expand Down Expand Up @@ -114,14 +117,14 @@ def _reconstruct_jobs_from_cache(self):
)
reconstructed_count += 1
except Exception as e:
print(f"Failed to reconstruct job for {cache_entry.repo_url}: {e}")
logger.error(f"Failed to reconstruct job for {cache_entry.repo_url}: {e}")

if reconstructed_count > 0:
print(f"Reconstructed {reconstructed_count} job statuses from cache")
logger.info(f"Reconstructed {reconstructed_count} job statuses from cache")
self.save_job_statuses()

except Exception as e:
print(f"Error reconstructing jobs from cache: {e}")
logger.error(f"Error reconstructing jobs from cache: {e}")

def save_job_statuses(self):
"""Save job statuses to disk."""
Expand All @@ -145,7 +148,7 @@ def save_job_statuses(self):

file_manager.save_json(data, self.jobs_file)
except Exception as e:
print(f"Error saving job statuses: {e}")
logger.error(f"Error saving job statuses: {e}")

def _worker_loop(self):
"""Main worker loop."""
Expand All @@ -157,7 +160,7 @@ def _worker_loop(self):
else:
time.sleep(1)
except Exception as e:
print(f"Worker error: {e}")
logger.error(f"Worker error: {e}")
time.sleep(1)

def _process_job(self, job_id: str):
Expand Down Expand Up @@ -187,7 +190,7 @@ def _process_job(self, job_id: str):
# Save job status to disk
self.save_job_statuses()

print(f"Job {job_id}: Using cached documentation")
logger.info(f"Job {job_id}: Using cached documentation")
return

# Clone repository
Expand Down Expand Up @@ -236,7 +239,7 @@ def _process_job(self, job_id: str):
# Save job status to disk
self.save_job_statuses()

print(f"Job {job_id}: Documentation generated successfully")
logger.info(f"Job {job_id}: Documentation generated successfully")

except Exception as e:
# Update job status with error
Expand All @@ -245,12 +248,12 @@ def _process_job(self, job_id: str):
job.error_message = str(e)
job.progress = f"Failed: {str(e)}"

print(f"Job {job_id}: Failed with error: {e}")
logger.error(f"Job {job_id}: Failed with error: {e}")

finally:
# Cleanup temporary repository
if 'temp_repo_dir' in locals() and os.path.exists(temp_repo_dir):
try:
subprocess.run(['rm', '-rf', temp_repo_dir], check=True)
except Exception as e:
print(f"Failed to cleanup temp directory: {e}")
logger.error(f"Failed to cleanup temp directory: {e}")