Skip to content

refactor: extract periodic task loop into reusable run_periodic_tasks#761

Open
ok300 wants to merge 2 commits intopubky:feat/dx-events-by-userfrom
ok300:claude/refactor-nexuswatcher-threads-zTRYp
Open

refactor: extract periodic task loop into reusable run_periodic_tasks#761
ok300 wants to merge 2 commits intopubky:feat/dx-events-by-userfrom
ok300:claude/refactor-nexuswatcher-threads-zTRYp

Conversation

@ok300
Copy link
Contributor

@ok300 ok300 commented Mar 5, 2026

This PR simplifies and modularizes NexusWatcher::start as follows:

  • the various parallel tasks are instantiated via PeriodicTask::new
  • the vector of PeriodicTask is given as arg to run_periodic_tasks
  • run_periodic_tasks spawns the tasks each in their own thread, registers the shutdown signal + the interval tick() + the cancellation signal

The cancellation signal is used by run_periodic_tasks to detect when a task has panicked. It then triggers a graceful shutdown from all other parallel running tasks.

This PR also uses the MissedTickBehavior::Skip for the run_periodic_tasks threads.


This PR is an alternative implementation for #757 and #760.

claude added 2 commits March 5, 2026 17:46
Set MissedTickBehavior::Skip on the interval timer in run_periodic_tasks
so that if a task takes longer than its tick interval, missed ticks are
dropped instead of queuing up a burst of back-to-back invocations.

Added tests verifying that slow tasks don't accumulate queued ticks and
that fast tasks still tick at the expected cadence.
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