[Engine] Implement context-aware online re-scheduling for constraint changes (activity and user scope)#173
Open
[Engine] Implement context-aware online re-scheduling for constraint changes (activity and user scope)#173
Conversation
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.
Description
This PR implements a context-aware online re-scheduling pipeline that reacts in real time to constraint changes. The system now understands constraint scope (activity vs. user), operation type (create/update/delete), and performs safe, minimal-disruption reassignment of affected activities. Key improvements include event-driven architecture, scope-aware matching logic, non-destructive reassignment with fallback staging, and comprehensive test coverage.
Related Issues
Fixes #172
Changes Made
Domain Messages (new)
ConstraintScopeenum (Activity, User) to distinguish constraint change contextsConstraintChangeOperationenum (Created, Updated, Deleted) to track mutation typeHandleConstraintChangeRequestrecord with scope, operation, activity ID, and user ID parameters for full event contextOnline Matching Strategy (refactored)
AppDbContextfor unified query execution and query filter control (IgnoreQueryFilters)HandleActivityConstraintChangeAsync(): revalidates single activity assignment and reschedules if invalidHandleUserConstraintChangeAsync(): discovers all affected assigned activities in period and reschedules invalid onesTryRescheduleAssignmentAsync():BuildCandidatesAsync(): filters available slot-resource pairsSelectCandidateAsync(): applies preference-weighted rankingGetExcludedSlotsAsync(): resolves constraint violationsIsAssignmentValidAsync(): checks assignment viabilityResolveSchedulingPeriodIdAsync(): handles optional period ID parameterConstraint Services
HandleConstraintChangeRequeston create/update/delete viaIMessagePublisherHandleConstraintChangeRequeston create/update/delete viaIMessagePublisherResolveSchedulingPeriodIdAsync()helper to ActivityConstraintService for activity → scheduling period lookupTest Coverage
ActivityConstraintServiceTests:IActivityRepository,ISubjectRepository,IMessagePublisherUserConstraintServiceTests:IMessagePublisherdependencyTesting
Test Instructions
dotnet test tests/Chronos.Tests.MainApianddotnet test tests/Chronos.Tests.EngineActivityConstraintServicepublishes event on create/update/delete via test assertionsUserConstraintServicepublishes event on create/update/delete via test assertionsChecklist
Database Changes
Configuration Changes
Deployment Notes
Ensure RabbitMQ connectivity is available on deployed environments for message publication. Verify that
IMessagePublisheris properly registered in dependency injection before deployment.Additional Context
This feature completes the online scheduling pipeline by ensuring constraint changes are consistently propagated and intelligently acted upon. The staged fallback strategy minimizes unnecessary schedule disruption, while non-destructive re-matching and explicit unresolved reporting provide operational safety and transparency.