Skip to content

Refactor: use dag package for cycle detection in scheduler#152

Merged
linyows merged 1 commit intomainfrom
refactor/use-dag-package-for-cycle-detection
Jan 18, 2026
Merged

Refactor: use dag package for cycle detection in scheduler#152
linyows merged 1 commit intomainfrom
refactor/use-dag-package-for-cycle-detection

Conversation

@linyows
Copy link
Owner

@linyows linyows commented Jan 18, 2026

Summary

  • Refactor cycle detection in scheduler.go to use the generic dag.DetectCycleFn function
  • Remove duplicated hasCycleDFS method, simplifying the codebase
  • Improve error messages to show the full cycle path (e.g., A -> B -> C)

Changes

  • scheduler.go: Rewrite checkCircularDependencies() to use dag package, remove hasCycleDFS()
  • scheduler_test.go: Add comprehensive tests for cycle detection

Test plan

  • Verify all existing tests pass
  • Verify newly added tests pass
  • Test cases: no cycle, 2-node cycle, 3-node cycle, self-reference, non-existent dependency, diamond dependency

🤖 Generated with Claude Code

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>
@linyows linyows requested a review from Copilot January 18, 2026 00:22
@github-actions

This comment has been minimized.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.DetectCycleFn from the dag package
  • Removed the hasCycleDFS helper 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.

@github-actions
Copy link

Code Metrics Report

main (1853798) #152 (627b432) +/-
Coverage 54.4% 54.4% -0.1%
Code to Test Ratio 1:1.0 1:1.0 +0.0
Test Execution Time 6s 11s +5s
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%)

Files Coverage +/- Status
scheduler.go 89.4% -1.6% modified

Reported by octocov

@linyows linyows merged commit acd8986 into main Jan 18, 2026
7 checks passed
@linyows linyows deleted the refactor/use-dag-package-for-cycle-detection branch January 18, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants