Repository navigation
Feat: automation dependencies - #2706
Conversation
…s end Context: - Only forecast runs followed their jobs, so schedule, report and plugin runs stayed at execution state 'pending' whatever became of their jobs. Change: - record_automation_run_jobs records the jobs such a run queued, then takes the outcome of any job that already finished or failed from Redis; a run with no jobs has succeeded. - The record_outcome_on_automation_run decorator records a job's start, success or failure on its run, found through the job's RQ ID, and wraps make_schedule, the sequential wrap-up job, run_report_job and execute_automation_job. - Plugin jobs carry automation_run_id in their trigger. - A schedule that fell back counts as a failed run, as the fallback job is not one of the run's recorded jobs. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Schedule, report and plugin runs now record how their jobs ended. Change: - Schedule runs, single and sequential, succeed once their jobs did and fail with the job's error; a job queued outside a run is not recorded. - A plugin run records its job's outcome, also when the job finished before the run recorded it. - Report run tests check the run's outcome: succeeded, nothing to do, and refused. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Schedule, report and plugin runs now record how their jobs ended, as forecast runs did. Change: - Say which jobs each type of run records, that a run without jobs has succeeded, and that a schedule which fell back counts as failed. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - main moved 11 commits on, including #2689, which saves what a data generator returns through generator_results and renames the unchecked-sensor errors to GeneratorWritesUncheckedSensor. Change: - Keep the record_outcome_on_automation_run imports next to main's new ones in data/automations.py and services/reporting.py. - Keep the decorator on make_schedule where main dropped ScheduleWritesUncheckedSensor. - The report refusal test expects GeneratorWritesUncheckedSensor as the run's error type. - The failed schedule test breaks the save through save_generator_results, which make_schedule now calls instead of save_to_db. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The v3.0-33 entry on run-stats said only forecast runs record their execution state, which PR #2670 makes untrue. Change: - Say execution state and job records are kept for every type of automation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - main moved 4 commits on, and #2647 changed the rq.job import in test_automations_fresh_db.py. Change: - Keep main's `from rq.job import Job, JobStatus` and this branch's `from sqlalchemy import select`. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Issue #2586: an automation consuming another's results could only be ordered by staggering cron strings Change: - New automation_dependency table, and 'waiting' and 'skipped' run states - A run waits for the upstream runs scheduled for the same time, and is dispatched once they ended, or skipped if one failed (unless failure is allowed) - Waiting runs are released when the upstream run ends, and by the runner's tick as a backstop - Dependencies are validated: same schedule, no cycles, readable upstream automations Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…copy Context: - Issue #2586 asks what a copy does with a dependency Change: - A copy waits for the copied upstream automation where that was copied too, and for the original one otherwise Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Issue #2586 Change: - depends-on on creating, updating and reading automations, and upstream-runs on run stats - PATCH checks the user may read the upstream automations, and refuses a schedule that breaks a dependency Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Issue #2586 Change: - add/edit automation take --depends-on and --allow-failure-of, edit also --no-dependencies - show automation lists dependencies, run-automations reports waiting and skipped runs Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Issue #2586 Change: - A 'Waits for' picker on the create and edit forms, copying the picked automation's schedule into the create form - The details panel lists the dependencies Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Issue #2586 Change: - Runner tests with a real worker: wait then release, skip, allow-failure, cascade, missed release, passed-over and inactive upstreams - Validation, API permission and schedule checks, CLI options, and copied dependencies Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Issue #2586 Change: - New section on dependencies, the waiting and skipped run states, and that a run on demand does not wait Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - PR #2706 Change: - Entry in 'Automations, in detail' and in the CLI changelog Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Resolve conflicts with the squash-merged #2670 and with #2657: take main's naming of schedule jobs and its job-failure path, keep the release of waiting runs where a run ends, and use AUTOMATION_RUN_RETRIED_TYPES, which now includes scheduling. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…tion bf22b21d0990 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A run now waits for each upstream automation's latest run due at or before its own scheduled time, by the upstream automation's own cron string and timezone, so for instance an hourly forecast can wait for meter data pulled every 15 minutes. The same-schedule check on creation and edit is dropped, and so is the UI copying the upstream schedule into the form. The run record names the time the upstream run was due at (due-at). Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
flexmeasures jobs run-automation --with-dependents, the trigger endpoint's with-dependents query parameter and the Automations page's Run with dependents start a run of the automation now, and a run for each active automation that waits for it, directly or through others, which waits for the runs started along with it, and is skipped if one of those failed. This is how a chain is re-run, for instance after backfilling the data at its start. A run records whether it was due by schedule or asked for on demand (trigger), so that on-demand runs can share a minute with scheduled runs, and a scheduled run only ever waits for scheduled upstream runs. The runner does not retry on-demand runs, as whoever started them is told when they fail. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
The details panel on the Automations page draws the automations listed there that this one waits for, on the left, and those that wait for it, on the right, directly or through others, with a dashed arrow where the waiting automation runs even when the one it waits for failed. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
The Waits for field in the creation and edit forms was a multiple select, which took Ctrl-clicks to pick several automations and cut long names off. Each automation is now a row with a tick box, naming its asset and recurrence, and dragging the corner of the list enlarges it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
v1.1.0 shipped without this feature, so its changelog entries move to new sections after it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ve out what may not be read A step lists the automations it waits for that do not run, too. What does not run along with an automation that does not run is listed, with the reason, rather than dropped without a word. An automation the user may not read is left out of the plan and of a chain run's response, so another organisation's automation ID is not given away. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…-on does Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…es not run Now that a step also lists what it waits for that does not run, only what was left out on purpose counts towards a branch to tick. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Messages said run(s), job(s) and automation(s); they now say one run or two runs. The confirmation of a run stayed on the page until it was reloaded; a toast suits it better. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
|
@Flix6x all seven are in. The monitor leaves waiting runs out ( |
Resolved conflicts with critical automations (#2856): an automation takes depends-on and critical together, in the API, the CLI and the page. When a run ends, the critical-failure hooks are told first, and then the runs waiting for it are released. A dispatch counts as given up by the same rule that releases those runs (see _dispatch_was_given_up), so a run on demand, which is never dispatched again, reaches the hooks, too. The dependencies migration now follows d4a17c6b3e92. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ailure hooks at once Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…s run Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…dependencies Runs follow the renamed revision column, so the migrations of this branch go on top of main's head (37aeaf745caa) rather than adding a merge migration. A refused run now also reaches whoever ran an automation on demand through a chain of runs (Run now, with-upstream and with-downstream), with each interface's own hint. Signed-off-by: Mohamed Belhsan Hmida
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Both changelogs conflicted only by entries added in the same place, so both are kept; in the API changelog the jobs `queue` filter goes above the Automations entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3SfN2GwxVNn1ws2ep Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x
left a comment
There was a problem hiding this comment.
Thanks Mohamed, all seven points are in, and the follow-up issues are there. I read the commits since my review (ffd245aac to a0ad01b45), then your merge of main with #2779 (24a1264f0, as a remerge diff), and ran the touched test files again.
flexmeasures monitor automationsleaves waiting runs out (dispatch_state != "waiting"), with a test.- Run now (and
flexmeasures jobs run-automation) records an on-demand run, solast-succeeded-atand the run history show it. - A step's
waits-forkeeps the upstreams that don't run, and the dialog says which step waits for them. - Automations you may not read are left out of the run plan and of
excluded; one that is named in a reason is "an automation". - No more "(s)":
pluralizeon the server, a smallcountOfon the page, and the confirmation is a toast. waited-for-bycarriesasset-name.excludedlists what goes along with an excluded automation ("Only runs for Solar forecast, which you left out." / "Waits for Battery schedule, which does not run.").
And thanks for #2913 (helping to start a chain) and #2914 (telling an owner about a skip caused by another organisation's automation).
The merge with #2779 looks right to me:
- Putting this branch's migrations on top of main's head (
37aeaf745caa) instead of adding a merge migration keeps one head (d5b8f3a1c962), and they now use main'srevisioncolumn throughout. - Telling "created after that" apart from "recurrence was reset" by
revision_started_at <= created_at, now that an edit of the definition also starts a revision, is the right test, and only a reset movesrevision_started_at. - A refused run now reaches whoever asked, from all three ways to run on demand (Run now,
with-upstream/with-downstreamin the API, and the CLI), each with its own hint, and the page tells you to tick Run as me.
I merged main in again (dce501070): only the two changelogs conflicted, by entries added in the same place, so both are kept. 412 tests in the touched files pass.
A suggestion, not for this PR: in run_automation_chain, when the automation that was asked for fails to queue its jobs (such as a RunsRefused), its error is raised from inside the loop, so the runs after it in claimed_runs are not dispatched. With with-downstream and an exclude, a downstream automation can wait for nothing in the chain (A → B → C, excluding B), and so start right away; if A is refused, C stays claimed until give_up_abandoned_on_demand_runs fails it as DispatchAbandoned, with a message that blames whoever asked. Dispatching the others first, or raising A's error after the loop, would let C run. Worth a small follow-up issue.
About the point I said I'd raise here, from my review of #2663: a run waiting for an upstream run that a bounded catch-up skipped should go ahead on the results it has, rather than be skipped. Only #2663's bound makes that kind of skip, and it records it with its own error type, so it belongs in #2663, which is stacked on this branch. Nothing needs to change here.
On merging: this one goes in before #2663, which targets this branch and will then move to main.
This branch held #2706 at 77d2fa2; main now has its final, squashed version (a3aa213). Resolved by taking main and applying this branch's own change on top of it (the diff from 77d2fa2 to f9b2cc1), which applied cleanly apart from the changelog, where both sides' entries are kept. Signed-off-by: F.N. Claessen <claessen@seita.nl> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3SfN2GwxVNn1ws2ep
…2663) * Skip missed automation runs older than a given bound skip_stale_automation_runs moves each automation's cursor past a due run that is older than the bound, without queueing it, so the automation resumes on its next scheduled run. It reuses the claim's compare-and-swap on the cursor, which is now factored out into _advance_cursor. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Let run-automations bound how old a caught-up run may be flexmeasures jobs run-automations --max-catchup <minutes> skips a missed run older than the bound, and reports it, while --max-catchup 0 skips every missed run and just resumes on the next scheduled one. Without the option, missed runs are still caught up however old they are. The docstring no longer says catch-up is limited to forecasts, as schedule and report automations catch up too. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Document bounding automation catch-up Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data/services/automations: record how schedule, report and plugin runs end Context: - Only forecast runs followed their jobs, so schedule, report and plugin runs stayed at execution state 'pending' whatever became of their jobs. Change: - record_automation_run_jobs records the jobs such a run queued, then takes the outcome of any job that already finished or failed from Redis; a run with no jobs has succeeded. - The record_outcome_on_automation_run decorator records a job's start, success or failure on its run, found through the job's RQ ID, and wraps make_schedule, the sequential wrap-up job, run_report_job and execute_automation_job. - Plugin jobs carry automation_run_id in their trigger. - A schedule that fell back counts as a failed run, as the fallback job is not one of the run's recorded jobs. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data/tests: cover how schedule, report and plugin runs end Context: - Schedule, report and plugin runs now record how their jobs ended. Change: - Schedule runs, single and sequential, succeed once their jobs did and fail with the job's error; a job queued outside a run is not recorded. - A plugin run records its job's outcome, also when the job finished before the run recorded it. - Report run tests check the run's outcome: succeeded, nothing to do, and refused. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs: every automation run records how its jobs ended Context: - Schedule, report and plugin runs now record how their jobs ended, as forecast runs did. Change: - Say which jobs each type of run records, that a run without jobs has succeeded, and that a schedule which fell back counts as failed. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * changelog: append PR #2670 to the durable automation runs entry Context: - Schedule, report and plugin runs now record how their jobs ended, not only forecast runs. Change: - Append PR #2670 to the #2457 entry, and drop "for its forecast jobs", which no longer holds. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs/api: run-stats records execution state for every automation type Context: - The v3.0-33 entry on run-stats said only forecast runs record their execution state, which PR #2670 makes untrue. Change: - Say execution state and job records are kept for every type of automation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data: let an automation's runs wait for the runs of other automations Context: - Issue #2586: an automation consuming another's results could only be ordered by staggering cron strings Change: - New automation_dependency table, and 'waiting' and 'skipped' run states - A run waits for the upstream runs scheduled for the same time, and is dispatched once they ended, or skipped if one failed (unless failure is allowed) - Waiting runs are released when the upstream run ends, and by the runner's tick as a backstop - Dependencies are validated: same schedule, no cycles, readable upstream automations Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data/services: copy an automation's dependencies along with an asset copy Context: - Issue #2586 asks what a copy does with a dependency Change: - A copy waits for the copied upstream automation where that was copied too, and for the original one otherwise Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * api/v3_0: name an automation's dependencies with depends-on Context: - Issue #2586 Change: - depends-on on creating, updating and reading automations, and upstream-runs on run stats - PATCH checks the user may read the upstream automations, and refuses a schedule that breaks a dependency Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * cli: --depends-on and --allow-failure-of for add and edit automation Context: - Issue #2586 Change: - add/edit automation take --depends-on and --allow-failure-of, edit also --no-dependencies - show automation lists dependencies, run-automations reports waiting and skipped runs Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: pick the automations an automation waits for on the automations page Context: - Issue #2586 Change: - A 'Waits for' picker on the create and edit forms, copying the picked automation's schedule into the create form - The details panel lists the dependencies Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * tests: automation dependencies in the runner, API, CLI and asset copies Context: - Issue #2586 Change: - Runner tests with a real worker: wait then release, skip, allow-failure, cascade, missed release, passed-over and inactive upstreams - Validation, API permission and schedule checks, CLI options, and copied dependencies Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs: how an automation waits for other automations Context: - Issue #2586 Change: - New section on dependencies, the waiting and skipped run states, and that a run on demand does not wait Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * changelog: automation dependencies Context: - PR #2706 Change: - Entry in 'Automations, in detail' and in the CLI changelog Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data/migrations: put automation dependencies after main's merge migration bf22b21d0990 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Let an automation wait for automations on another schedule A run now waits for each upstream automation's latest run due at or before its own scheduled time, by the upstream automation's own cron string and timezone, so for instance an hourly forecast can wait for meter data pulled every 15 minutes. The same-schedule check on creation and edit is dropped, and so is the UI copying the upstream schedule into the form. The run record names the time the upstream run was due at (due-at). Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Run an automation on demand along with the automations waiting for it flexmeasures jobs run-automation --with-dependents, the trigger endpoint's with-dependents query parameter and the Automations page's Run with dependents start a run of the automation now, and a run for each active automation that waits for it, directly or through others, which waits for the runs started along with it, and is skipped if one of those failed. This is how a chain is re-run, for instance after backfilling the data at its start. A run records whether it was due by schedule or asked for on demand (trigger), so that on-demand runs can share a minute with scheduled runs, and a scheduled run only ever waits for scheduled upstream runs. The runner does not retry on-demand runs, as whoever started them is told when they fail. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: draw the chain an automation is part of in its details The details panel on the Automations page draws the automations listed there that this one waits for, on the left, and those that wait for it, on the right, directly or through others, with a dashed arrow where the waiting automation runs even when the one it waits for failed. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: pick the automations to wait for from a list of tick boxes The Waits for field in the creation and edit forms was a multiple select, which took Ctrl-clicks to pick several automations and cut long names off. Each automation is now a row with a tick box, naming its asset and recurrence, and dragging the corner of the list enlarges it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: let a chain of automations link to them and explain itself on hover Clicking an automation in a chain opens its details on the page of its own asset. Hovering over an automation tells its type, asset and recurrence, and hovering over an arrow what a failure does. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Have the runner find out how a job ended that could not report it A killed job never recorded its outcome, which left its run unfinished, and everything waiting for that run waiting forever. On each tick, the runner now looks up the unfinished jobs in Redis, and records what became of them. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs: say that a recurrence can change while automations depend on it The PATCH description said it could not, which was never the case. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Name an upstream automation that is not listed alongside the one waiting for it The chain, the details and the edit form only had its ID, so they could not link to it. Automation responses now give its name and asset to whoever may read it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Run an automation along with what it waits for Run with ascendants brings one automation up to date: what it waits for runs first, and what waits for it does not run. What may not be run is left out and reported, and a new run-plan endpoint tells what a run would come down to. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: show what a chain comes down to before running it Run with ascendants joins the actions, and both ways of running a chain now show the IDs that run, in order, first. Branches above an automation can be left out there, and what will not run says why. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: show a validation error as a sentence rather than as JSON Refusing a dependency that would close a loop showed the raw response in the edit form. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Warn about what waits for an automation before deleting it It then runs without it, which was easy to miss, so the page and the CLI name those automations first. They can be on other assets, so an automation's details now report waited-for-by. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: choose which automations the Waits for lists and chains go by One selector offers those on the page, on this asset only, on public assets, or every automation you can see. The latter two come from a new listing across assets, of what the user may read. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: let a chain drawing show all automations in scope Next to the chain of the automation being read, its details can now also draw the automations that have nothing to do with it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: say so when the Waits for list is empty It used to be a blank box. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui: do not say that a run queued 0 jobs while its chain goes on An automation with nothing new to do still sets off what waits for it, which read as if nothing happened. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Give the actual reason for not copying a schedule automation It blamed the automation's parameters, which hold no sensor references: its flex config can. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Answer an unreadable automation like one that does not exist Waiting for an automation gave 403 for another organisation's and 422 for an unknown ID, which told which IDs exist. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Name chain runs upstream and downstream, and list what is excluded with-ascendants and with-dependents become with-upstream and with-downstream, leave-out becomes exclude, and run-plan takes include=upstream|downstream instead of direction, in the API, the CLI and the Automations page. The run plan lists only what runs under steps, and the rest under excluded with the reason, which now includes "You left it out.". Both directions share one chain function, so exclude works downstream too, a trigger lists every run under runs, and the steps come in chain order, also for a diamond. The page asks the server for the plan again when a branch is ticked, rather than working it out itself. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Exclude a downstream automation the user may not run, rather than refusing the chain Waiting for an automation only takes reading it, so another organisation could keep its owner from running Run with downstream, with a 403, and the owner could not remove that dependency. Such an automation is now excluded, along with what can only be reached through it, as upstream already did. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Page through automations across assets, rather than cutting them off at 500 GET /assets/automations takes page and per-page, like GET /assets, and reports num-records with a page; without page, it lists them all. What the caller may not read is dropped before paging, so a page holds as many automations as asked for while there are more. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Report waited-for-by only when asked for with include=waited-for-by Unlike depends-on, it is derived from other automations, costs a query across them, and can name IDs in organisations the caller cannot read. The Automations page asks for it before deleting an automation, which is what it is for. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Go ahead after an upstream reset, and wait for the run an upstream caught up with Reactivating an upstream automation, or giving it another cron string or timezone, reset its cursor to about now, so a run waiting for one of its earlier due times found it passed over and was skipped, for up to a day with a daily upstream. An automation now records when its current revision started, and a due time before it counts as not scheduled, so what waits for it goes ahead. After a runner outage, the missed upstream runs are coalesced into the latest one, which a run waiting for an earlier one now waits for, rather than being skipped. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Release a run on demand of an inactive automation, and cancel waiting runs on deactivation Running an inactive automation with what is upstream of it ran its upstream automations, but left its own run waiting for ever, as neither the release nor the runner looked at waiting runs of inactive automations. A run on demand is now released whether its automation is active or not. Deactivating an automation cancels its scheduled runs that are still waiting, which would otherwise go ahead late on reactivation, and what waits for them goes ahead without them, as for an inactive automation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Say in a sentence what became of each upstream run a run waits for Each upstream run a run waits for gets a summary, such as "Solar forecast (automation 3, run 4) failed." or "... was not due yet at 2026-08-05 13:00 UTC, as it was created after that.", in the times of the upstream automation's own clock. The skip reason and the waiting message are made of these, rather than bare IDs and states, and the skip reason names only the runs it was skipped for. The Automations page shows the summaries of the latest run. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Label the chain runs Run up to here and Run from here Their tooltips say the automation chain runs up to, or from, this automation, as do the titles of the plans they show first. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Say when each excluded automation last succeeded, and warn when it never did The run plan's excluded automations come with the steps that wait for them, and with when they last succeeded, as those steps go by the results they produced then. The plan shown before a chain runs says so per excluded automation, rather than "The rest goes by the latest results of those that won't run", and warns where one never succeeded, as what waits for it will likely fail, without keeping the chain from running. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Print what run-automations reconciled and released, not "No automations due" A tick that failed a killed job's run, and skipped or set off the runs waiting for it, printed "No automations due", so an operator watching the cron log saw nothing. The runner's tick now reports each run it ended for a job that ended without saying so, and each run that released as a result, in that order, with the run's own message, and "No automations due" only when nothing happened. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Name the scopes to wait for by what they hold "Automations on this page" and "Automations on this asset only" become "This asset and the assets below it" and "This asset only", and without the automations of the assets below it listed, which makes the two the same, only "This asset only" is offered. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Say under a mixed allow-failure box what it stands for Where the automations it waits for differ, the box's mixed state looked unticked, so a line under it names each of them with yes or no, and says that ticking or unticking sets all of them. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Show what an automation waits for, and what waits for it, apart from its sensors flexmeasures show automations --id said "Depends on" for automations right next to "Reads from" for sensors, which read alike. It now says "Waits for", with each one's recurrence and timezone, as those decide which of their runs are waited for, adds "Waited for by", and heads the sensor lists "Sensors it reads" and "Sensors it writes". Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * End a run on demand whose dispatch was abandoned, and what waits for it A run on demand left claimed, such as by an API process that went down between recording a chain of runs and queueing the first, was never retried, as only scheduled runs are, and never counted as given up, so its chain waited for ever. The runner now fails such a run once the claim on it expires, which skips what waits for it, and reports it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Keep a job's recorded success when it fails afterwards, while releasing what waits for its run A job releases the runs waiting for its run once it recorded its outcome, which counts against its own timeout. Running out of time there had the queue's exception handler fail the job after all, and with it the run, so that what still waited for it was skipped. A recorded success now stands, and a runner releases what the job did not get to on its next tick. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Record a run skipped by the catch-up bound, and bound unfinished runs too A missed run older than --max-catchup is now claimed and ended as a 'skipped' run with error type MissedRunTooOld, so it shows up with the automation's runs and the runs waiting for it learn it will not deliver. A run a runner left before queueing any job is skipped likewise when older than the bound; one that queued part of its jobs is left to queue the rest. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Name runs on the automation's own clock in run-automations, and cap --max-catchup The run lines of flexmeasures jobs run-automations show each run's time in the automation's timezone, so an operator recognises the run. A --max-catchup of more than a year is refused, where it overflowed the datetime it is subtracted from. The catch-up CLI test now uses the fresh-db fixtures, as main's CLI tests do. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Document the catch-up bound as a restart option, its recorded skips, and changelog it under v1.2.0 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Let a run skipped by the catch-up bound not stop what waits for it An upstream run skipped for being older than a runner's --max-catchup counted as failed, so every run waiting for it was skipped too: after an 08:30 restart with --max-catchup 60, a skipped 06:00 price check took the hourly battery schedules down with it. Not catching up was the operator's choice, so such a run now counts as 'not-scheduled', like one canceled by deactivation, and what waits for it goes ahead on the results it has. Its record says the upstream run was skipped by the catch-up bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3SfN2GwxVNn1ws2ep Signed-off-by: F.N. Claessen <claessen@seita.nl> * Never skip the runs of a critical automation by the catch-up bound, and count the minutes in words --max-catchup now leaves critical automations out, both their missed runs and the runs a runner left unfinished: an organisation counts on what they produce, so they are caught up however old the runs are. The docs, the option's help and the changelogs say so. The skip messages say "60 minutes" (and "1 minute") instead of "minute(s)". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3SfN2GwxVNn1ws2ep Signed-off-by: F.N. Claessen <claessen@seita.nl> --------- Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> Signed-off-by: F.N. Claessen <claessen@seita.nl> Co-authored-by: F.N. Claessen <claessen@seita.nl> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…picker fix) into feat/2901-automation-tabs-in-use Kept both sides where they met: - a plugin type's examples (this branch) and its source model (the source picker fix); - deleting an automation first asks the server what waits for it (main, #2706), and still leaves the toast for the last automation of a plugin type (this branch). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3SfN2GwxVNn1ws2ep Signed-off-by: F.N. Claessen <claessen@seita.nl>
Main's automation dependencies (#2706) brought a `_current_user_may_read` for automations, so the one checking whether you may see the user you name is renamed `_current_user_may_see_user`; otherwise the later definition replaced it. The API change log line for `run-as` moves along with the #2779 lines into v3.0-38, as v3.0-37 was released with v1.1.3. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Description
An automation can now wait for the automations whose results it uses, instead of relying on staggered cron strings.
For example, a data pull feeds a report, which feeds a forecast.
allow-failure).--with-dependents,?with-dependents=true) re-runs a whole chain, for example after a backfill.--with-ascendants,?with-ascendants=true) brings one automation up to date: what it waits for runs first, it runs last, and what waits for it does not run.run-planendpoint. Branches above an automation can be left out there (leave-out), and what will not run says why, such as an automation on a public asset.GET /assets/automations?scope=public|all, which lists what you may read, 500 at most.waited-for-by.depends-on, CLI--depends-on/--allow-failure-of/--no-dependencies, and a UI Waits for list of tick boxesname,assetandasset-nameof each upstream automation the caller may read. One they may not read stays a bare ID.automation_dependencytable,waiting/skippedrun states, and a runtrigger(scheduleoron-demand)documentation/changelog.rstdocumentation/cli/change_log.rstdocumentation/api/change_log.rstUnlike the approach on the issue, runs wait in the database rather than through RQ's
depends_on, for two reasons:depends_onpassed through.A waiting run is released as soon as its upstream run ends.
A job reports its own outcome, which it cannot do when it is killed, so the runner asks Redis about the jobs that are still unfinished.
RQ fails a job whose work-horse died, and one whose worker disappeared once its heartbeat lapsed.
A job that left Redis without reporting counts as failed, and a job that is still queued or running is left alone, however long it takes.
A chain run on demand records a run per automation, so its runs can wait for each other.
They wait only for the runs started with them, and never for scheduled ones.
Running with ascendants can have several starting points, one per branch, and each starts right away.
An automation that does not run takes along what is above it, as nothing would use those results, and what waits for it goes by the results it already has.
No permission changes here: running needs permission to manage automations, so a normal user sees a public automation as one that won't run.
The unique index on runs now covers scheduled runs only, so an on-demand run can share a minute with a scheduled one.
The runner does not retry on-demand runs.
Look & Feel
How to test
pytest flexmeasures/data/tests/test_automation_dependencies_fresh_db.py flexmeasures/api/v3_0/tests/test_automation_dependencies_api_fresh_db.py flexmeasures/ui/tests/js/test_automation_chain.py, plus the dependency tests incli/tests/test_automations.pyandtest_asset_copy_automations_fresh_db.py.kill -9the work-horse of a running job, and runflexmeasures jobs run-automations: its run fails with the reason, and what waits for it is released.Further Improvements
skippedruns.Related Items
Closes #2586. Part of #2557.
Sign-off