Route remote command polling through TaskScheduler#592
Merged
bjorkert merged 1 commit intofeature/remote-command-pollingfrom Apr 10, 2026
Merged
Conversation
Replace the parallel Timer with a .remoteCommandPoll TaskScheduler task so the aggressive post-remote-command polling runs through the same scheduler as every other recurring fetch. The tick reschedules .deviceStatus and .treatments to fire immediately, then reschedules itself for the next interval. Parked at .distantFuture when the window closes (timeout or fresh data detected). Drop .fetchBG from the polled set: no remote command produces a BG entry, and the completion signature doesn't look at bgData, so the fetch was dead weight during the window.
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
Timer.scheduledTimerused for post-remote-command polling with a new.remoteCommandPollTaskSchedulertask, so the aggressive polling runs through the same scheduler as every other recurring fetch in the app..deviceStatusand.treatmentsto fire immediately and reschedules itself for the next 3s interval. The task is parked at.distantFuturewhen the window closes (timeout or fresh data detected) — the same transient resting state every task already passes through between fire and reschedule..fetchBGfrom the polled set: no remote command produces a BG entry, andRemoteCommandDataSignaturedoesn't inspectbgData, so the fetch was dead weight during the window.Why
TimercalledbgTaskAction/deviceStatusAction/treatmentsTaskActiondirectly every 3s, each of which internallyrescheduleTask'd itself back to its normal cadence — a continuous double-reschedule war.TaskScheduler's lifecycle applies; no separateTimerlifecycle to reason about.deinittimer invalidation needed —TaskSchedulerowns the lifetime.Safety notes
.remoteCommandPollis lazily registered only whenstartRemoteCommandPollingis called from the.remoteCommandSucceedednotification.scheduleAllTasks()is not touched, so no app refresh/reset path will accidentally spawn it.TaskID.allCasesis only iterated infireOverdueTasks, which filters onnextRun <= now. A parked.distantFutureentry is skipped forever until an explicitrescheduleTaskrevives it.MainViewControlleris the app root VC, but thescheduleTaskclosure uses[weak self]as a belt-and-suspenders guard against any future refactor that deinits it.