[docs]classNaiveLivenessSubjectState(BaseModel):"""Holds the internal state of the target subject. Will be attached as an attribute to the said subject, but only used by the liveness implementation."""failure_score:int=0success_score:int=0
[docs]@overridedefsuccess(self,subject:LivenessSubject)->bool:"""Returns a boolean indicating if a state change happened."""state=self.get_state_of(subject)state.success_score+=1state.failure_score=0ifstate.success_score>=self.settings.success_threshold:returnself.set_status_as_up_if_necessary(subject)returnFalse
[docs]@overridedeffailure(self,subject:LivenessSubject,reason:Optional[str]=None)->bool:"""Returns a boolean indicating if a state change happened."""state=self.get_state_of(subject)state.success_score=0state.failure_score+=1self.add_failure_reason(subject,reason)ifstate.failure_score>=self.settings.failure_threshold:returnself.set_status_as_down_if_necessary(subject)returnFalse