flexmeasures.data.services.automations
Logic for running automations (see also the CLI command flexmeasures jobs run-automations).
Functions
- flexmeasures.data.services.automations.describe_cronstr(cronstr: str) str
Describe a cron string in natural language, e.g. “At 06:00”.
Explicitly renders times in 24-hour format, as cron-descriptor otherwise picks a format based on the system locale.
- flexmeasures.data.services.automations.floor_to_minute(dt: datetime) datetime
Floor a datetime to the minute, in the FLEXMEASURES_TIMEZONE.
- flexmeasures.data.services.automations.get_automation_job_stats(automation: Automation) dict[str, int]
Count the jobs created by this automation, per job status.
Note that jobs in Redis have a limited TTL, so this only counts fairly recent jobs.
- flexmeasures.data.services.automations.get_due_automations(now: datetime | None = None) list[Automation]
Return active automations whose cron string matches the given (or current) minute.
Cron strings are interpreted in the FLEXMEASURES_TIMEZONE.
- flexmeasures.data.services.automations.prepare_schedule_trigger_message(parameters: dict, asset_id: int) dict
Complete stored schedule parameters into a message for the AssetTriggerSchema.
The asset id is injected, and the (required) schedule start defaults to now, floored to the message’s resolution (if given, otherwise to the minute), so recurring automations produce fresh schedules on each run.