Refactor monitoring loops to use IntervalAction utility#20
Merged
Conversation
Replaces hand-rolled `while (!ct.IsCancellationRequested) { ...; await
Task.Delay(refreshInterval, ct); }` loops in MemFragService,
MachineMonitorService, and BuildMonitorService with
`ktsu.IntervalAction`, which provides the same fixed-interval polling
semantics out of the box and prevents overlapping executions when a
tick takes longer than the interval.
Fixes #12.
ktsu.IntervalAction.IntervalAction exposes Stop() but does not implement IDisposable, so the using-declaration form fails to compile. Stop() at end of scope is sufficient to halt the polling thread.
The string-to-strong-path migration in MergeService, FileExplorerService, and CodeGenService dropped the Ensure.NotNull check on the path parameter. The new build pipeline treats CA1062 as an error, so the analyzer flags every public method that dereferences a non-nullable reference parameter without validating it. Re-add the checks that the migration deleted.
Spectre.Console.Cli only binds multi-value command options to T[]; List<string>/IReadOnlyList<string> won't bind. Suppressing the analyzer here is the only viable option.
|
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
Refactored three monitoring services to use the
ktsu.IntervalActionlibrary instead of manual while-loop implementations withTask.Delay. This improves code maintainability and provides a more robust pattern for periodic task execution.Key Changes
IntervalActionfor hardware sensor dashboard updatesIntervalActionfor process memory monitoring, added linked cancellation token to handle process exit eventsIntervalActionfor build status monitoring, changed async call to synchronous execution within the tick actionktsu.IntervalActionpackage (v1.3.10) to three project filesImplementation Details
Tick()action that performs the monitoring workIntervalAction.Start()is called withActionIntervalandPollingIntervalset to the refresh intervalTask.Delay(Timeout.InfiniteTimeSpan, ct)instead of looping with delaysOperationCanceledExceptionand callingticker.Stop()computerCapture,processCapture) are used to ensure closure semantics work correctly with the tick actionhttps://claude.ai/code/session_015nyEtaBBNsbsoQHsboGddE