Refactor: use dag package for cycle detection in scheduler#152
Merged
Conversation
Replace the duplicated cycle detection implementation in JobScheduler with the generic dag.DetectCycleFn function. This eliminates code duplication and improves error messages by showing the full cycle path. - Remove hasCycleDFS method from JobScheduler - Use dag.DetectCycleFn for cycle detection - Improve error message to show full cycle path (e.g., "A -> B -> C") - Add comprehensive tests for cycle detection Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the scheduler's cycle detection logic to use a generic DAG utility, eliminating code duplication and improving error messages with full cycle paths.
Changes:
- Replaced custom DFS cycle detection with
dag.DetectCycleFnfrom the dag package - Removed the
hasCycleDFShelper method to reduce code duplication - Enhanced error messages to display complete cycle paths (e.g., "A -> B -> C")
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| scheduler.go | Refactored checkCircularDependencies() to use dag package and removed hasCycleDFS() method |
| scheduler_test.go | Added comprehensive test cases covering various dependency scenarios including cycles, self-references, and diamond patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Metrics Report
Details | | main (1853798) | #152 (627b432) | +/- |
|---------------------|----------------|----------------|-------|
- | Coverage | 54.4% | 54.4% | -0.1% |
| Files | 63 | 63 | 0 |
| Lines | 6382 | 6375 | -7 |
- | Covered | 3477 | 3469 | -8 |
+ | Code to Test Ratio | 1:1.0 | 1:1.0 | +0.0 |
| Code | 12579 | 12570 | -9 |
+ | Test | 13462 | 13547 | +85 |
- | Test Execution Time | 6s | 11s | +5s |Code coverage of files in pull request scope (90.9% → 89.4%)
Reported by octocov |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
dag.DetectCycleFnfunctionhasCycleDFSmethod, simplifying the codebaseA -> B -> C)Changes
scheduler.go: RewritecheckCircularDependencies()to use dag package, removehasCycleDFS()scheduler_test.go: Add comprehensive tests for cycle detectionTest plan
🤖 Generated with Claude Code