declutter icon indicating copy to clipboard operation
declutter copied to clipboard

Improve rule execution scheduling

Open midnightdim opened this issue 5 months ago • 0 comments

Version: 1.13.x

Description

Currently, all rules are executed every X minutes according to a single global interval.
This approach is:

  • Inefficient — rules that don’t need frequent execution still run.
  • Inflexible — rules that need faster checks can’t override the interval.

Proposed improvements

  1. Store the last execution time (last_run_ts) for each rule.
  2. Allow per-rule schedule configuration (optional, falls back to global default).
  3. Calculate next execution time for each rule based on its last run + interval.
  4. Replace the fixed global timer with a dynamic scheduler that wakes only for the nearest due execution.

Expected benefits

  • Reduced CPU wake-ups and unnecessary processing.
  • More flexible scheduling per rule.
  • Scales better with a larger set of rules.

Implementation notes (high-level)

  • DB schema update: add exec_interval (nullable) and last_run_ts (INTEGER) to rules table.
  • Scheduler logic: compute the nearest next_run_ts and set timer accordingly.
  • UI: add interval override option in rule edit form.
  • Keep the global default interval in settings to use as fallback.

midnightdim avatar Aug 14 '25 12:08 midnightdim