diff options
-rwxr-xr-x | jobmanager.py | 1 | ||||
-rwxr-xr-x | jobs/JobBase.py | 8 | ||||
-rw-r--r-- | jobstate.py | 7 |
3 files changed, 13 insertions, 3 deletions
diff --git a/jobmanager.py b/jobmanager.py index 1683e2c..5b3505f 100755 --- a/jobmanager.py +++ b/jobmanager.py @@ -69,6 +69,7 @@ class JobManager: if lastRunStatus.CurrentStateSuccess == False and \ thisJob.notifyOnFailureEvery() == JobBase.JobFailureNotificationFrequency.ONSTATECHANGE and \ lastRunStatus.NumFailures >= thisJob.numberFailuresBeforeNotification(): + logging.info("Notifying of success (state change). " + str(lastRunStatus.NumFailures) + " >= " + str(thisJob.numberFailuresBeforeNotification())) if not thisJob.onStateChangeSuccess(): emailWorks = False lastRunStatus.markSuccessful() diff --git a/jobs/JobBase.py b/jobs/JobBase.py index 7658a37..4ac1f0d 100755 --- a/jobs/JobBase.py +++ b/jobs/JobBase.py @@ -86,8 +86,12 @@ class JobBase(object): return True return False elif notifyFrequency == JobFailureNotificationFrequency.ONSTATECHANGE: - #Only notify if the last JobState was a Success - return jobState.CurrentStateSuccess + if minFailureCount == 1: + # If we notify on the first failure, only notify if the last JobState was a Success + return jobState.CurrentStateSuccess + else: + # If we notify after N failures, only notify if this is exactly the nth failure + return 1 + currentFailureCount == minFailureCount return True """Helper method to send email""" diff --git a/jobstate.py b/jobstate.py index a8e6542..f3e7796 100644 --- a/jobstate.py +++ b/jobstate.py @@ -14,6 +14,8 @@ class JobState: self.NumFailures = 0 def markFailedAndNotify(self): + # Confusing: In this function 'self' represents the lastRunStatus + # and we know the current run has failed if self.CurrentStateSuccess: self.CurrentStateSuccess = False self.FirstFailureTime = time.time() @@ -24,8 +26,9 @@ class JobState: self.NumFailures += 1 def markFailedNoNotify(self): + # Confusing: In this function 'self' represents the lastRunStatus + # and we know the current run has failed if self.CurrentStateSuccess: - logging.warn("Somehow we called markFailedNoNotify, on a success condition, without notifying the user") self.CurrentStateSuccess = False self.FirstFailureTime = time.time() self.LastNotifyTime = 0 @@ -34,6 +37,8 @@ class JobState: self.NumFailures += 1 def markSuccessful(self): + # Confusing: In this function 'self' represents the lastRunStatus + # and we know the current run has succeeded if self.CurrentStateSuccess: pass else: |