Repository navigation
docs: add a complete plugin automation example - #2705
Conversation
Show the test plugin in full as the example of an automation type, and explain what __data_generator_base__ and __version__ mean for stored automations, which processes need the plugin enabled, and how to create and try out an automation with config and parameter files. Closes #2610 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Walk through the example the way the other customisation sections do, keeping only what the code does not already show, and point to the automations docs for the add automation command instead of repeating it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
joyshmitz
left a comment
There was a problem hiding this comment.
Thanks for this. Including the tested mock_ingestion plugin with literalinclude keeps the example in step with code the test suite runs. I applied both commits onto current main (they apply cleanly) and checked the walkthrough against the code there.
Checked against main
- The included module is the plugin the test suite uses:
test_plugin_loader_discovers_declared_automationloads it throughFLEXMEASURES_PLUGINS, and the run tests register its handler and execute it (flexmeasures/data/tests/test_plugin_automations_fresh_db.py, plus the API, CLI and UI test modules). The PR changes only its docstring. - Unknown fields:
load_automation_payloadloads config and parameters withschema.load(payload, unknown=RAISE)(flexmeasures/data/automations.py:29), andresolve_plugin_generatordoes the same for a run's parameters (line 367). This overrides a schema's ownMeta.unknown, so dropping the advice to setunknown=RAISEis correct. - Data source and version:
get_data_source_info()sets the source type from__data_generator_base__(flexmeasures/data/models/data_sources.py:260),create()stores the version from the generator's__version__(flexmeasures/data/automations.py:138), andresolve_plugin_generatorrefuses to run when it differs from the installed version, telling the user to recreate the automation (lines 354-357). - Undeclared outputs: before saving, the worker raises
GeneratorWritesUncheckedSensorfor any result on a sensor outside the declared outputs (check_generator_resultsinflexmeasures/data/services/generator_results.py). - Blueprint: when a plugin defines none,
register_plugins()logs "No blueprints found for plugin ..." and skips the plugin, so its__automation_types__are never registered (flexmeasures/utils/plugin_utils.py:152-156). - The YAML examples use the schemas' field names (
sensor,value). - The strict docs build (
sphinx-build -W --keep-going -n) renders the whole module intoplugin/customisation.htmland reports no warning on the lines this PR adds. The one warning in that file, an unresolved :class:DataGeneratoron line 418, predates the PR; since the PR touches this section,:class:~flexmeasures.data.models.data_sources.DataGenerator`` resolves it.
Suggestions
- The linked CLI example does not match the plugin. The new text sends readers to :ref:
automationsforflexmeasures add automation, but the plugin example there still uses--type site-ingestion(documentation/features/automations.rst:180), the identifier of theSiteIngestorexample this PR removes; the example plugin registersmock-ingestion. That command also creates the automation active (the default,flexmeasures/cli/data_add.py:1811and1989), while the text asks readers to verify one run "before activating its recurrence". Showing the full command next to the YAML files, with--type mock-ingestionand--inactive, makes the walkthrough runnable as written. It could also say thatsensorhas to belong to the automation's asset or one of its descendants, which every run checks (flexmeasures/data/automations.py:334-342). - Which
__version__. The example module defines__version__twice: on the module (line 14) and onMockIngestionGenerator(line 29). The automation's version comes from the generator class (flexmeasures/data/automations.py:138); the module's is whatregister_plugins()records as the plugin version (flexmeasures/utils/plugin_utils.py:142). Saying "the generator class's__version__" tells readers which one to raise. - Queue names. A handler's
queuehas to be one offorecasting,scheduling,ingestionorreporting(flexmeasures/utils/job_utils.py:15); any other name fails registration with "Unknown automation queue" (flexmeasures/data/automations.py:282-283). The example usesingestion, so it works, but one sentence keeps plugin authors from inventing their own queue. - Changelog. The PR template asks for a changelog item, and documentation PRs such as #2597 and #2721 have one. The existing line on plugin automation types in
documentation/changelog.rst(line 267, crediting #2553 and #2644) could credit #2705 as well. - Nested schemas (nit). "Unknown fields in the configuration or parameters are always refused" holds for top-level fields. A
fields.Nestedschema keeps its ownMeta.unknown: withEXCLUDEthere, an extra nested key is dropped silently despite the outerunknown=RAISE. "Unknown top-level fields are always refused" is exact. - Optional. The removed closing sentence, that permissions and output scope are checked again when a run is queued and computed, still holds on
main: queueing checks the run user's access (flexmeasures/data/services/automations.py:2544-2545) and the output scope (flexmeasures/data/automations.py:211), and the worker repeats both before computing (lines 426-427). It could stay.
Note for maintainers: #2779 (open) makes an automation's config editable and moves the automation to the data source the new config resolves to. Whichever of the two merges second should check whether "existing automations need to be recreated" still holds.
Context: - The linked automations page uses another type and creates the automation active, so the walkthrough could not be followed as written. Change: - Show the full command with the example's type and --inactive. - State that the sensor must belong to the automation's asset or one of its descendants. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The example defines __version__ twice, and only the generator class's version is stored with an automation. - Registration refuses queues outside the known set. - A nested schema keeps its own handling of unknown fields. Change: - Name the generator class's __version__. - List the allowed queues. - Limit the unknown fields note to top-level fields. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The strict docs build warns that :class:`DataGenerator` has no target. Change: - Use the full path, which links to the class's API page. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
|
Thanks, the three new commits cover the points from my review. I checked them against current The changelog item is the one point left. With v1.1.0 released, it would go into the next release's section, which |
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Description
mock_ingestionin full, so the example is tested and cannot drift from the code.DataGenerator,input_sensors/output_sensors,_compute, and the__automation_types__registration.__data_generator_base__and__version__mean for stored automations, including that raising__version__makes existing automations fail until they are recreated.FLEXMEASURES_PLUGINS, and that a plugin needs a Blueprint to be registered.flexmeasures jobs run-automation.unknown=RAISE: FlexMeasures already refuses unknown fields when it loads the config and parameters, so plugin schemas don't need to set it.Look & Feel
New sub-sections under Plugin Customization → Adding your own automation type:
How to test
Build the docs and open
plugin/customisation.html. The example code should render in full.Further improvements
Related Items
Closes #2610
Sign-off