-
-
Notifications
You must be signed in to change notification settings - Fork 52
feat : add Parallel Task Execution for Multi-Step Installs #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e2e0d91
feat : add Parallel Task Execution for Multi-Step Installs
Sahilbhatane d6dd23d
Suggestion fix
Sahilbhatane 3957f15
Fix: make tests portable on Windows
Sahilbhatane d96994b
test: update CLI install call expectations
Sahilbhatane 422d890
chore: fix ruff typing/import formatting
Sahilbhatane 1993398
[security] Centralize dangerous patterns
Sahilbhatane c13cba5
Merge branch 'main' into issue-269
Sahilbhatane b509bab
Fix executor type hint
Sahilbhatane 4fd7da8
Fix tests and lint
Sahilbhatane 2e6dd08
Merge branch 'main' into issue-269
Sahilbhatane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,7 +285,14 @@ def doctor(self): | |
| doctor = SystemDoctor() | ||
| return doctor.run_checks() | ||
|
|
||
| def install(self, software: str, execute: bool = False, dry_run: bool = False): | ||
| def install( | ||
| self, | ||
| software: str, | ||
| execute: bool = False, | ||
| dry_run: bool = False, | ||
| parallel: bool = False, | ||
| ): | ||
| # Validate input first | ||
| is_valid, error = validate_install_request(software) | ||
| if not is_valid: | ||
| self._print_error(error) | ||
|
|
@@ -371,6 +378,82 @@ def progress_callback(current, total, step): | |
|
|
||
| print("\nExecuting commands...") | ||
|
|
||
| if parallel: | ||
| import asyncio | ||
|
|
||
| from cortex.install_parallel import run_parallel_install | ||
|
|
||
| def parallel_log_callback(message: str, level: str = "info"): | ||
| if level == "success": | ||
| cx_print(f" ✅ {message}", "success") | ||
| elif level == "error": | ||
| cx_print(f" ❌ {message}", "error") | ||
| else: | ||
| cx_print(f" ℹ {message}", "info") | ||
|
Comment on lines
+386
to
+392
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add type hints to inline callback function. The 🔎 Add type hints- def parallel_log_callback(message: str, level: str = "info"):
+ def parallel_log_callback(message: str, level: str = "info") -> None:
if level == "success":
cx_print(f" ✅ {message}", "success")
elif level == "error":
cx_print(f" ❌ {message}", "error")
else:
cx_print(f" ℹ {message}", "info")As per coding guidelines, type hints are required for all functions. 🤖 Prompt for AI Agents |
||
|
|
||
| try: | ||
| success, parallel_tasks = asyncio.run( | ||
| run_parallel_install( | ||
| commands=commands, | ||
| descriptions=[f"Step {i + 1}" for i in range(len(commands))], | ||
| timeout=300, | ||
| stop_on_error=True, | ||
| log_callback=parallel_log_callback, | ||
| ) | ||
| ) | ||
|
|
||
| total_duration = 0.0 | ||
| if parallel_tasks: | ||
| max_end = max( | ||
| (t.end_time for t in parallel_tasks if t.end_time is not None), | ||
| default=None, | ||
| ) | ||
| min_start = min( | ||
| (t.start_time for t in parallel_tasks if t.start_time is not None), | ||
| default=None, | ||
| ) | ||
| if max_end is not None and min_start is not None: | ||
| total_duration = max_end - min_start | ||
|
|
||
| if success: | ||
| self._print_success(f"{software} installed successfully!") | ||
| print(f"\nCompleted in {total_duration:.2f} seconds (parallel mode)") | ||
|
|
||
| if install_id: | ||
| history.update_installation(install_id, InstallationStatus.SUCCESS) | ||
| print(f"\n📝 Installation recorded (ID: {install_id})") | ||
| print(f" To rollback: cortex rollback {install_id}") | ||
|
|
||
| return 0 | ||
|
|
||
| failed_tasks = [ | ||
| t for t in parallel_tasks if getattr(t.status, "value", "") == "failed" | ||
| ] | ||
| error_msg = failed_tasks[0].error if failed_tasks else "Installation failed" | ||
|
|
||
| if install_id: | ||
| history.update_installation( | ||
| install_id, | ||
| InstallationStatus.FAILED, | ||
| error_msg, | ||
| ) | ||
|
|
||
| self._print_error("Installation failed") | ||
| if error_msg: | ||
| print(f" Error: {error_msg}", file=sys.stderr) | ||
| if install_id: | ||
| print(f"\n📝 Installation recorded (ID: {install_id})") | ||
| print(f" View details: cortex history show {install_id}") | ||
| return 1 | ||
|
|
||
| except Exception as e: | ||
| if install_id: | ||
| history.update_installation( | ||
| install_id, InstallationStatus.FAILED, str(e) | ||
| ) | ||
| self._print_error(f"Parallel execution failed: {str(e)}") | ||
| return 1 | ||
|
|
||
| coordinator = InstallationCoordinator( | ||
| commands=commands, | ||
| descriptions=[f"Step {i+1}" for i in range(len(commands))], | ||
|
|
@@ -751,6 +834,11 @@ def main(): | |
| install_parser.add_argument("software", type=str, help="Software to install") | ||
| install_parser.add_argument("--execute", action="store_true", help="Execute commands") | ||
| install_parser.add_argument("--dry-run", action="store_true", help="Show commands only") | ||
| install_parser.add_argument( | ||
| "--parallel", | ||
| action="store_true", | ||
| help="Enable parallel execution for multi-step installs", | ||
| ) | ||
|
|
||
| # History command | ||
| history_parser = subparsers.add_parser("history", help="View history") | ||
|
|
@@ -824,7 +912,12 @@ def main(): | |
| elif args.command == "status": | ||
| return cli.status() | ||
| elif args.command == "install": | ||
| return cli.install(args.software, execute=args.execute, dry_run=args.dry_run) | ||
| return cli.install( | ||
| args.software, | ||
| execute=args.execute, | ||
| dry_run=args.dry_run, | ||
| parallel=args.parallel, | ||
| ) | ||
| elif args.command == "history": | ||
| return cli.history(limit=args.limit, status=args.status, show_id=args.show_id) | ||
| elif args.command == "rollback": | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.