flexmeasures.data.automations

Registered automation handlers and the worker for plugin data generators.

Functions

flexmeasures.data.automations.check_execution_access(automation, sensors)

Recheck the API creator’s current permissions 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)

Compute and persist declared results with provenance in a plugin-enabled worker.

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)

Resolve the declared generator and sensors without sharing mutable run state.

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 _create_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.

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.