fix: Split backend pre_conversion/analyzer.py (26K) + batch/queue_manager.py (22K) — post-#1769 split regrowth - #1904
Conversation
Addresses post-split regrowth from anchapin#1769 by extracting logic into dedicated files: - pre_conversion/rules.py and file_checks.py for scan rules and file-type validation - batch/queue_backend.py for Redis/Celery adapter, leaving queue_manager.py as orchestration only Fixes anchapin#1871
There was a problem hiding this comment.
Sorry @webbrain-one, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Reviewer's GuideThis PR continues the post-#1769 backend split by extracting Redis/Celery queue integration and pre-conversion scanning logic into focused service modules, improving separation of concerns and making batch/queue_manager.py and pre_conversion/analyzer.py thinner orchestration layers. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce coupling and prevent “regrowth” of large backend modules by extracting pre-conversion scan rules/file checks and batch queue broker adapters into dedicated service modules.
Changes:
- Added
pre_conversion/rules.pyto centralize static scan rule definitions. - Added
pre_conversion/file_checks.pyto host per-file-type validation helpers. - Added
batch/queue_backend.pyto encapsulate Redis/Celery broker interactions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| backend/src/services/pre_conversion/rules.py | Introduces a rules data model and initial regex-based scan rules. |
| backend/src/services/pre_conversion/file_checks.py | Adds helper functions for validating manifests/resource packs and scanning asset directories. |
| backend/src/services/batch/queue_backend.py | Adds Redis job-state/progress publishing and Celery submit/poll wrappers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| """Scan-rule definitions extracted from pre_conversion/analyzer.py (Issue #1871). | ||
|
|
||
| This module centralizes static analysis rules, regex patterns, and AST-based | ||
| heuristics used to detect compatibility issues, unsupported APIs, and risky | ||
| code patterns during the pre-conversion scan phase. | ||
| """ |
| class RuleSeverity(Enum): | ||
| """Severity levels for pre-conversion scan rules.""" | ||
| ERROR = auto() | ||
| WARNING = auto() | ||
| INFO = auto() | ||
|
|
| id="PRE-001", | ||
| name="Forge API Usage", | ||
| severity=RuleSeverity.ERROR, | ||
| pattern=re.compile(r"import\s+net\.minecraftforge", re.IGNORECASE), |
| """Validate pack.mcjson for Bedrock compatibility prerequisites. | ||
|
|
||
| Returns a dictionary with compatibility flags and missing dependencies. | ||
| """ | ||
| result: dict[str, Any] = {"compatible": True, "missing": []} | ||
| pack_file = pack_path / "pack.mcjson" | ||
| if not pack_file.exists(): | ||
| return result | ||
|
|
||
| try: | ||
| with open(pack_file, encoding="utf-8") as f: | ||
| data = json.load(f) | ||
| if data.get("pack_format", 0) < 2: | ||
| result["compatible"] = False | ||
| result["missing"].append("pack_format >= 2") | ||
| except json.JSONDecodeError as e: | ||
| result["compatible"] = False | ||
| result["missing"].append(f"Invalid JSON in pack.mcjson: {e}") | ||
| return result |
| if "modLoader" in content or "loaderVersion" in content: | ||
| issues.append("Legacy FML manifest detected; may require manual mapping.") |
| """Walk asset directory and flag files with unsupported extensions or sizes. | ||
|
|
||
| Returns a list of problematic file paths. | ||
| """ |
| def publish_progress(self, job_id: str, progress: float, message: str = "") -> None: | ||
| """Emit progress update via Redis channel.""" | ||
| payload = json.dumps({"job_id": job_id, "progress": progress, "message": message}) | ||
| self._redis.publish(f"progress:{job_id}", payload) |
| def poll_result(self, task_id: str) -> dict[str, Any] | None: | ||
| """Check task completion status without blocking.""" | ||
| from celery.result import AsyncResult # noqa: PLC0415 | ||
| async_result = AsyncResult(task_id, app=self._app) | ||
| if async_result.ready(): | ||
| return {"status": async_result.status, "result": async_result.get(timeout=0)} | ||
| return None |
Closes #1871
Summary by Sourcery
Extract queue broker integration and pre-conversion analysis responsibilities into dedicated backend service modules to reduce coupling and prepare for further splitting of large files.
New Features: