Catch up on missed automation runs - #2292
Conversation
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
Documentation build overview
17 files changed ·
|
|
Closing this in favour of #2396, which has now been merged into #2290. I checked what would be lost, and the catch-up behaviour is covered:
The two approaches differ in where the state lives, and that is the main reason this one is the One idea from here does survive, and I did not want it lost with the PR: |
Problem
flexmeasures jobs run-automationswas stateless: if the host's cron missed a minute (downtime, overload), automations due in that minute were silently skipped forever.Solution
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.--max-catchupoption (in minutes, default 60) bounds how far back the runner looks;0disables catching up. Without a recorded last tick (first run), only the current minute is processed.Changes
flexmeasures/data/services/automations.py: newget_due_automations_in_window(start, end)returning each due automation once, with its due minutes (DST-safe minute iteration);get_due_automationsnow delegates to it.flexmeasures/cli/jobs.py: catch-up window computation,--max-catchupoption, last-tick bookkeeping, updated help text.commands.rstone-liner, CLI changelog bullet.--max-catchupbounding (incl.0disabling catch-up), and first-run behavior.🤖 Generated with Claude Code
https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX