core.mixins.HealthModelMixin module

Module with the HealthMixin.

class core.mixins.HealthModelMixin.HealthModelMixin(*args, **kwargs)[source]

Bases: Model

Mixin adding a health functionality to a model class.

is_healthy

Flags whether the model instance is subject to errors. None by default.

last_error

The latest error in connection with the model instance.

last_error_occurred_at

The time of occurrence of the latest error.

class Meta[source]

Bases: object

Metadata class for the mixin, abstract to avoid makemigrations picking it up.

abstract = False
_meta = <Options for HealthModelMixin>
set_unhealthy(errormessage)[source]

Sets the is_healthy flag to False and adds the last_error and its time.

Only saves if the model is already in the database.

Parameters:

errormessage (str | Exception) – The error causing the health change or its message.

Return type:

None

set_healthy()[source]

Sets the is_healthy flag to True.

Runs only if the model is not already healthy. Only saves if the model is already in the database.

Return type:

None