flexmeasures.data.automations
Registered automation handlers and the worker for plugin data generators.
Functions
- flexmeasures.data.automations.check_execution_access(automation, sensors)
Recheck the current permissions of the user whom the automation runs as (its creator, unless taken over), for unattended execution.
A null identity denotes trusted CLI creation or a legacy automation. A deleted identity remains stored and fails closed, rather than reverting to CLI trust.
- flexmeasures.data.automations.execute_automation_job(automation_id: int, data_source_id: int, parameters: dict) dict
Compute and persist declared results with provenance in a plugin-enabled worker.
The job computes with the data source and the parameters it was queued with, also when the automation has been edited since, the way a job of a built-in type does. Its sensors are still checked against the access of the user whose access the automation’s runs check now. The job’s result lists its outputs as a report job’s result does (see run_report_job).
- flexmeasures.data.automations.get_automation_handler(type_id: str) AutomationHandler
Resolve a trusted handler, failing safely when its plugin is unavailable.
- flexmeasures.data.automations.get_automation_types() dict[str, AutomationHandler]
Return the handlers available in this application.
- flexmeasures.data.automations.initialize_automation_handlers(app)
Install built-in handlers in this application’s registry.
- flexmeasures.data.automations.load_automation_payload(schema: Schema, payload: dict, field: str) dict
Load a strict plugin schema and retain the payload’s field in errors.
- flexmeasures.data.automations.register_automation_handler(app, handler: AutomationHandler)
Register trusted plugin code, rejecting ambiguous types and generators.
- flexmeasures.data.automations.resolve_plugin_generator(automation, handler, parameters=None, source=None)
Resolve the declared generator and sensors without sharing mutable run state.
- Parameters:
source – the data source to compute with, such as the one a run was planned with; defaults to the automation’s own.
- flexmeasures.data.automations.user_has_permission(user, entity, permission: str) bool
Whether a given user, rather than the one making the request, holds a permission on an entity.
- flexmeasures.data.automations.validate_automation_type(type_id: str)
Validate creation against the current registry, not a static type list.
- flexmeasures.data.automations.validate_output_scope(asset_id, sensors)
Require plugin results to stay within the automation’s asset subtree.
Classes
- class flexmeasures.data.automations.AutomationHandler(type_id: str, display_name: str, generator_class: type[DataGenerator] | None = None, queue: str = 'ingestion', result_noun: str = 'result')
Declare a type backed by a generator with configuration and parameter schemas.
Plugins expose instances in
__automation_types__. Generator sensor properties must enumerate every sensor read or written by the computation. Credentials belong in server settings, never configuration or parameters persisted by this handler.- __init__(type_id: str, display_name: str, generator_class: type[DataGenerator] | None = None, queue: str = 'ingestion', result_noun: str = 'result') None
- _generator_from_source(source, check_permissions: bool, config_given: bool) DataGenerator
Set up this type’s data generator from an existing data source, as the user named it.
The built-in types do this in _prepare_builtin_automation, and a type registered by a plugin is held to the same rules.
- create(**kwargs)
Validate and create the automation without committing it.
- installed_generator_version() str
The version of the generator class this server has, as a data source records it.
- prepare(asset, cronstr: str, timezone: str | None = None, parameters: dict | None = None, generator_class: str | None = None, config: dict | None = None, source=None, check_permissions: bool = False, source_is_kept: bool = False, kept_sensor_ids: dict[str, set[int]] | None = None)
Validate an automation’s definition, and look up or create the data source storing its generator config.
Creating an automation and editing one both go through here, so an edit is held to the same rules as a creation. See _prepare_builtin_automation for the parameters.
- Returns:
a PreparedAutomation.
- run(automation, automation_run=None, scheduled_at=None)
Queue work using only registered code and committed identifiers.
A durable run (see dispatch_automation_run) carries the parameters and the jobs its run was planned with, which the built-in types read to pick up where an earlier attempt at the same run stopped. A plugin type’s run is dispatched with the parameters its run was planned with, and records its one job once queued, so that the run follows how the job ends.
Exceptions
- exception flexmeasures.data.automations.AutomationPayloadValidationError(message: str | list | dict, field_name: str = '_schema', data: Mapping[str, Any] | Iterable[Mapping[str, Any]] | None = None, valid_data: list[Any] | dict[str, Any] | None = None, **kwargs)
A plugin payload error that identifies configuration versus run parameters.