aboutsummaryrefslogtreecommitdiff
path: root/jobstate.py
diff options
context:
space:
mode:
authorTom Ritter <tom@ritter.vg>2016-01-31 13:22:08 -0600
committerTom Ritter <tom@ritter.vg>2016-01-31 13:22:08 -0600
commit3bea3bae59e7404b286b5bf97a6270270bfadd6c (patch)
treec9d1d7cf76681420587198d09abda761912c47c4 /jobstate.py
parent1a8b46d940d3a4bc06700d15307191bb10008ea6 (diff)
Refactor lots of things to allow you to be notified every so often, instead of every single time.
Diffstat (limited to 'jobstate.py')
-rw-r--r--jobstate.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/jobstate.py b/jobstate.py
new file mode 100644
index 0000000..4df0de0
--- /dev/null
+++ b/jobstate.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import time
+import logging
+import datetime
+
+class JobState:
+ def __init__(self, name):
+ self.name = name
+ self.CurrentStateSuccess = True
+
+ def markFailedAndNotify(self):
+ if self.CurrentStateSuccess:
+ self.CurrentStateSuccess = False
+ self.FirstFailureTime = time.time()
+ self.LastNotifyTime = self.FirstFailureTime
+ else:
+ self.LastNotifyTime = time.time()
+
+ def markFailedNoNotify(self):
+ 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
+ else:
+ pass
+
+ def markSuccessful(self):
+ if self.CurrentStateSuccess:
+ pass
+ else:
+ self.CurrentStateSuccess = True
+ self.FirstFailureTime = 0
+ self.LastNotifyTime = 0
+
+ def serialize(self):
+ ret = self.name + "|"
+ ret += "Succeeding" if self.CurrentStateSuccess else "Failing"
+ ret += "|" + str(self.FirstFailureTime)
+ ret += "|" + str(self.LastNotifyTime)
+ return ret
+
+ @staticmethod
+ def Parse(line):
+ s = JobState()
+
+ line = line.strip()
+ parts = line.split("|")
+
+ s.name = parts[0]
+ s.CurrentStateSuccess = True if parts[1] == "Succeeding" else False
+ s.FirstFailureTime = float(parts[2])
+ s.LastNotifyTime = float(parts[3])
+
+ return s
+
+ @staticmethod
+ def Empty(name):
+ s = JobState(name)
+ return s \ No newline at end of file