Skip to content

Refactor monitoring loops to use IntervalAction utility#20

Merged
matt-edmondson merged 5 commits into
mainfrom
claude/work-on-open-issues-PXazd
May 9, 2026
Merged

Refactor monitoring loops to use IntervalAction utility#20
matt-edmondson merged 5 commits into
mainfrom
claude/work-on-open-issues-PXazd

Conversation

@matt-edmondson
Copy link
Copy Markdown
Contributor

Summary

Refactored three monitoring services to use the ktsu.IntervalAction library instead of manual while-loop implementations with Task.Delay. This improves code maintainability and provides a more robust pattern for periodic task execution.

Key Changes

  • MachineMonitorService: Replaced while-loop with IntervalAction for hardware sensor dashboard updates
  • MemFragService: Replaced while-loop with IntervalAction for process memory monitoring, added linked cancellation token to handle process exit events
  • BuildMonitorService: Replaced while-loop with IntervalAction for build status monitoring, changed async call to synchronous execution within the tick action
  • Dependencies: Added ktsu.IntervalAction package (v1.3.10) to three project files

Implementation Details

  • Each service now defines a Tick() action that performs the monitoring work
  • IntervalAction.Start() is called with ActionInterval and PollingInterval set to the refresh interval
  • The main task now waits indefinitely on Task.Delay(Timeout.InfiniteTimeSpan, ct) instead of looping with delays
  • Cancellation is handled by catching OperationCanceledException and calling ticker.Stop()
  • In MemFragService, a linked cancellation token source is used to handle both external cancellation and process exit events
  • Local variable captures (computerCapture, processCapture) are used to ensure closure semantics work correctly with the tick action

https://claude.ai/code/session_015nyEtaBBNsbsoQHsboGddE

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.
@matt-edmondson matt-edmondson enabled auto-merge May 6, 2026 14:40
claude and others added 4 commits May 6, 2026 14:44
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.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
3.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@matt-edmondson matt-edmondson merged commit 02033e9 into main May 9, 2026
6 of 8 checks passed
@matt-edmondson matt-edmondson deleted the claude/work-on-open-issues-PXazd branch May 9, 2026 06:07
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