Skip to content

Catch up on missed automation runs#2292

Draft
Flix6x wants to merge 1 commit into
feat/2288-automations-for-forecastsfrom
feat/2288-run-automations-catchup
Draft

Catch up on missed automation runs#2292
Flix6x wants to merge 1 commit into
feat/2288-automations-for-forecastsfrom
feat/2288-run-automations-catchup

Conversation

@Flix6x

@Flix6x Flix6x commented Jul 11, 2026

Copy link
Copy Markdown
Member

Problem

flexmeasures jobs run-automations was stateless: if the host's cron missed a minute (downtime, overload), automations due in that minute were silently skipped forever.

Solution

  • The runner now remembers the last processed minute in Redis (key automation-runner:last-tick, set after each invocation completes). On each invocation, it processes every minute from just after the last tick through the current minute.
  • A new --max-catchup option (in minutes, default 60) bounds how far back the runner looks; 0 disables catching up. Without a recorded last tick (first run), only the current minute is processed.
  • An automation due in several missed minutes still runs only once per invocation: its timing parameters (e.g. forecast start) are resolved against the current time, so queueing multiple identical jobs would be wasteful.
  • The per-(automation, minute) Redis guard keys are kept, and now acquired for every due minute of an automation, so concurrent invocations (also with overlapping catch-up windows) cannot double-queue jobs.

Changes

  • flexmeasures/data/services/automations.py: new get_due_automations_in_window(start, end) returning each due automation once, with its due minutes (DST-safe minute iteration); get_due_automations now delegates to it.
  • flexmeasures/cli/jobs.py: catch-up window computation, --max-catchup option, last-tick bookkeeping, updated help text.
  • Docs: catch-up semantics in the "Automating forecasts" section, commands.rst one-liner, CLI changelog bullet.
  • Tests: catch-up queues a missed automation once, once-per-invocation for an every-minute cron, --max-catchup bounding (incl. 0 disabling catch-up), and first-run behavior.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX

Track the last processed minute in Redis (automation-runner:last-tick).
If previous invocations of `flexmeasures jobs run-automations` missed
some minutes (e.g. due to host downtime or overload), the next
invocation also matches automations against the missed minutes, bounded
by a new --max-catchup option (60 minutes by default; 0 disables).

An automation due in several missed minutes still runs only once per
invocation, as its timing parameters are resolved against the current
time, so queueing multiple identical jobs would be wasteful. The
per-(automation, minute) Redis guard keys still protect against
concurrent invocations, also over overlapping catch-up windows.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
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.

1 participant