flexmeasures.data.services.automation_monitoring
Find the automation runs that failed, so that monitoring can report them.
Also find the runs skipped because an automation they wait for failed in another organisation, or on a public asset, whose failure is otherwise only reported to that organisation, or to the host.
Functions
- flexmeasures.data.services.automation_monitoring.get_unalerted_failed_automation_runs(stuck_after: timedelta, now: datetime | None = None) list[FailedAutomationRun]
Return the automation runs that failed and were not reported yet, oldest first.
A run failed when its execution failed, when its execution has been running for longer than
stuck_after, or when its dispatch failed and will not be attempted again. This holds for every automation type, although only the types that record their execution can fail on it. Runs of an automation that opted out of monitoring are left out, and stay unreported until it opts back in.- Parameters:
stuck_after – How long a run may execute before it counts as stuck.
now – The moment to judge by, which defaults to the server’s current time.
- flexmeasures.data.services.automation_monitoring.get_unreported_cross_organisation_skips() list[SkippedAutomationRun]
Return the runs skipped because a run they wait for failed in another organisation, or on a public asset, and not reported yet.
The failed run is reported to its own organisation (or, on a public asset, to the host), so the organisation of the skipped run would otherwise not hear about it. Only the first skipped run of each organisation along a chain is returned, with the runs of its organisation skipped because of it, which a skip within one organisation does not get reported for. Runs of an automation that opted out of monitoring are left out, as their failures are.
- flexmeasures.data.services.automation_monitoring.get_users_to_notify(failures: list[AutomationFailures], skips: list[AutomationSkips] = ()) list[tuple[User, list[AutomationFailures], list[AutomationSkips]]]
Return who should hear about which failed and skipped automations, in a digest of their own.
Those are the account admins of each asset’s organisation and the consultants of its consultancy organisation, as long as they are active, have an email address and may read the automation. Automations on public assets have no organisation, so only the host hears about them.
- Parameters:
failures – The failed runs, collapsed per automation.
skips – The runs skipped because of another organisation’s automation, collapsed per automation.
- Returns:
Each user to notify, ordered by ID, with the failures and skips that user may read, in the given order.
- flexmeasures.data.services.automation_monitoring.group_failed_runs_by_automation(failed_runs: list[FailedAutomationRun]) list[AutomationFailures]
Collapse failed runs per automation, keeping the order in which the automations first appear.
- flexmeasures.data.services.automation_monitoring.group_skipped_runs_by_automation(skipped_runs: list[SkippedAutomationRun]) list[AutomationSkips]
Collapse skipped runs per automation, keeping the order in which the automations first appear.
Classes
- class flexmeasures.data.services.automation_monitoring.AutomationFailures(automation: Automation, failed_runs: list[FailedAutomationRun] = <factory>)
The failed runs of one automation, collapsed into what a digest says about them.
- __init__(automation: Automation, failed_runs: list[FailedAutomationRun] = <factory>) None
- property first_run: AutomationRun
The failed run that was due first.
- property last_error: str | None
The error of the most recent failed run that recorded one, if any did.
- property last_run: AutomationRun
The failed run that was due most recently.
- property runs_failed_while_unmonitored: list[AutomationRun]
The failed runs that were due before monitoring was last switched back on.
Had the automation been monitored then, an earlier digest would have reported them.
- class flexmeasures.data.services.automation_monitoring.AutomationSkips(automation: Automation, skipped_runs: list[SkippedAutomationRun] = <factory>)
The skipped runs of one automation, collapsed into what a digest says about them.
- __init__(automation: Automation, skipped_runs: list[SkippedAutomationRun] = <factory>) None
- property first_run: AutomationRun
The skipped run that was due first.
- property last_skipped_run: SkippedAutomationRun
The skipped run that was due most recently.
- property runs: list[AutomationRun]
The skipped runs, along with the runs skipped because of them, which a digest reports at once.
- class flexmeasures.data.services.automation_monitoring.FailedAutomationRun(run: AutomationRun, reason: str)
An automation run that failed, with the way it failed.
- __init__(run: AutomationRun, reason: str) None
- class flexmeasures.data.services.automation_monitoring.SkippedAutomationRun(run: AutomationRun, upstream_runs: list[AutomationRun], skipped_after: list[AutomationRun])
A run skipped because a run it waits for failed in another organisation, or on a public asset.
Within its own organisation, it is the first run skipped along that chain. The runs of its organisation skipped because of it come along, as they are not reported on their own.
- __init__(run: AutomationRun, upstream_runs: list[AutomationRun], skipped_after: list[AutomationRun]) None