Skip to content

Support automation dependencies and chain runs #281

Open

Description

@Flix6x

FlexMeasures#2706 (open, not yet milestoned) lets an automation wait for the automations whose results it uses, and adds endpoints to run or inspect a whole chain.
Once it is merged, the client should cover it, building on the automation methods of #230.
This was left out of scope in #228.

Server changes (API v3.0-35, per #2706's API changelog)

  • POST /assets/<id>/automations and PATCH /assets/<id>/automations/<automation-id> accept depends-on, a list like [{"automation": 7, "allow-failure": false}]. Responses report it, each upstream automation the caller may read coming with its name, asset and asset-name.
  • GET /assets/<id>/automations/<automation-id> reports waited-for-by.
  • POST /assets/<id>/automations/<automation-id>/trigger accepts with-dependents=true, or with-ascendants=true with an optional leave-out list of automation IDs (not both).
    With dependents, the response adds dependent-runs.
    With ascendants, it has no job, but runs (each with automation, run and dispatch-state) and left-out.
  • New GET /assets/<id>/automations/<automation-id>/run-plan?direction=ascendants|dependents, which lists the steps a chain run would take, without running anything.
  • New GET /assets/automations?scope=public|all, which lists automations across assets (500 at most).

Plan

  • add_automation(..., depends_on=None): send depends-on only when given. Accept the API's list of dicts as is, so new keys need no client release.
  • update_automation(asset_id, automation_id, depends_on=[...]) already works, as keyword arguments are passed on in kebab-case (Add automation methods #230). Document it, with an example, and add a test.
  • trigger_automation(..., with_dependents=False, with_ascendants=False, leave_out=None): send the query parameters only when set, and refuse both flags together before sending anything.
    Its check that the response has a job must not apply with ascendants, where the response has none.
  • trigger_and_await_automation: with ascendants or dependents there is no single job to wait for, so either refuse those flags here, or wait for the runs some other way. To be decided. #2706 tracks runs, not jobs, so this may need a way to look up a run's state.
  • get_automation_run_plan(asset_id, automation_id, direction) → the steps list.
  • get_automations_in_scope(scope="all") (name to be decided) for GET /assets/automations.
  • Version gating: as in Add automation methods #230, on a 404, say which server version is needed. Use the FlexMeasures release that ships #2706, once it is known. For the new trigger parameters and depends-on there is no 404, so check the version with server_version_at_least before sending them, and raise InsufficientServerVersionError on an older server, rather than letting it reject an unknown field.
  • Tests with aioresponses, and an end-to-end run against a local server on #2706's branch, covering a two-automation chain triggered with ascendants and with dependents.
  • Docs: a "Chaining automations" section in docs/automations.rst, plus a changelog entry.

Also: a naming mismatch to fix along the way

In add_automation, the automation_type argument becomes the API's type.
In update_automation, the same name passed as a keyword is sent as automation-type, which the server refuses as an unknown field.
That is harmless while the type cannot be changed, but confusing.
Either map automation_type to type in update_automation, too, or say in its docstring that keyword names are the API's field names in snake_case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions