User Flow Exceptions
The Rule Framework includes special exceptions to control how a flow ends. These exceptions can be imported from the ewx_public package. Below, you can find a summary of their behavior regarding the generated data in the flow and some examples.
The legacy imports (from energyworx_public.domain import FlowCancelException) are still supported on the platform. See ewx-public Package for the full migration guide.
| Exception | Raised When | Save Data | Create Tasks | Trigger Flows | Flow Metadata |
|---|---|---|---|---|---|
| FlowCancelException | User wants to cancel the whole flow | No | No | No | Yes |
| FlowStopException | User wants to stop the flow execution at that point | Yes | Yes | Yes | Yes |
FlowCancelException
Use this to completely stop a flow if something's wrong with the data. Everything the flow did is undone, and any triggered chained flows won't be executed.
This exception will normally be logged as an error in audit events. However, it has a parameter (show_exception_as_warning) that allows it to be logged in the audit events as a warning instead.
from ewx_public.exceptions import FlowCancelException
from ewx_public.flow_rule import FlowRule
class MyRule(FlowRule):
def apply(self, **kwargs):
...
# It will log the error message in audits event as warning instead of an error.
raise FlowCancelException("My error message", show_exception_as_warning=True)
...
FlowStopException
Use this to stop the flow but keep the results it produced so far. All the data (timeseries, tags, flow properties) that was saved until this point will be persisted, and any chained flows triggered before this exception will be executed.
...
from ewx_public.exceptions import FlowStopException
from ewx_public.flow_rule import FlowRule
...
class MyRule(FlowRule):
def apply(self, **kwargs):
...
# It will log the message in audit events as info. It will set the Flow Status to 'stopped'.
raise FlowStopException("Some explanation about why the flow was stopped")
This exception will be logged as info in the audit events.