aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ritter <tom@ritter.vg>2016-01-31 14:56:27 -0500
committerTom Ritter <tom@ritter.vg>2016-01-31 14:56:27 -0500
commite7c15ef06e7886f69cee15863d7f75dc75c9ecec (patch)
treea0c8a89062e62d61db24c025e51e3dfe731c2660
parent618c3606a1f5f230124a937201e53589dbab1260 (diff)
Get custom state names for each of the jobs now
-rw-r--r--README.md4
-rwxr-xr-xjobmanager.py2
-rwxr-xr-xjobs/HTTPServerChecker.py1
-rwxr-xr-xjobs/JobBase.py6
-rwxr-xr-xjobs/PeerChecker.py1
-rwxr-xr-xjobs/TCPServerChecker.py1
6 files changed, 11 insertions, 4 deletions
diff --git a/README.md b/README.md
index 9f3de2c..96a71a8 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,9 @@ JobBase is the base for a job, and should be used when you have a single, custom
### Inherit JobSpawner
-JobSpawner should be used when you want to run the same logic for multiple servers. Look at HTTPServerChecker and TCPServerChecker for examples of how one can use it.
+JobSpawner should be used when you want to run the same logic for multiple servers. Look at HTTPServerChecker and TCPServerChecker for examples of how one can use it.
+
+Be sure to call JobBase.__init__(self, config, ...) in the inner JobBase's init (with all of your arguements); otherwise the job state file will get messed up and be unable to distinguish between your individual spawned jobs.
# Install
diff --git a/jobmanager.py b/jobmanager.py
index a53a84e..9bfb2d3 100755
--- a/jobmanager.py
+++ b/jobmanager.py
@@ -50,7 +50,7 @@ class JobManager:
", making up a dummy state for it.")
lastRunStatus = self.state[thisJob.getStateName()] = JobState.Empty(thisJob.getStateName())
- logging.info("Executing " + thisJob.getName())
+ logging.info("Executing " + thisJob.getName() + "(" + thisJob.getStateName() + ")")
if not thisJob.execute():
#Unsuccessful run
logging.info("Execution of " + thisJob.getName() + " failed")
diff --git a/jobs/HTTPServerChecker.py b/jobs/HTTPServerChecker.py
index ec2a9d6..965e977 100755
--- a/jobs/HTTPServerChecker.py
+++ b/jobs/HTTPServerChecker.py
@@ -14,6 +14,7 @@ class HTTPServerChecker(JobSpawner.JobSpawner):
class ServerChecker(JobBase.JobBase):
def __init__(self, config, url, frequency, failureNotificationFrequency):
+ JobBase.JobBase.__init__(self, config, url, frequency, failureNotificationFrequency)
self.config = config
self.url = url
self.frequency = frequency
diff --git a/jobs/JobBase.py b/jobs/JobBase.py
index 29ca443..416f28d 100755
--- a/jobs/JobBase.py
+++ b/jobs/JobBase.py
@@ -2,6 +2,7 @@
import time
import random
+import hashlib
import logging
import datetime
@@ -21,8 +22,9 @@ class JobFailureNotificationFrequency:
ONSTATECHANGE = "state_change"
class JobBase:
- def __init__(self, config):
+ def __init__(self, config, *args):
self.config = config
+ self.stateName = hashlib.sha1(self.getName() + "|" + "|".join(args)).hexdigest()
""" Return a friendly name to identify this Job"""
def getName(self):
@@ -32,7 +34,7 @@ class JobBase:
Needed to keep track of the job's run history.
Takes into account the contructor arguments to uniquely identify JobSpawner-jobs"""
def getStateName(self):
- return self.getName()
+ return self.stateName
"""Returns True if the job should execute this cron-run"""
def shouldExecute(self, cronmode):
diff --git a/jobs/PeerChecker.py b/jobs/PeerChecker.py
index 12ce8d8..d271419 100755
--- a/jobs/PeerChecker.py
+++ b/jobs/PeerChecker.py
@@ -13,6 +13,7 @@ import JobSpawner
class PeerChecker(JobSpawner.JobSpawner):
class IndividualPeerChecker(JobBase.JobBase):
def __init__(self, config, checkurl, notificationAddress):
+ JobBase.JobBase.__init__(self, config, checkurl, notificationAddress)
self.checkurl = checkurl
self.notificationAddress = notificationAddress
diff --git a/jobs/TCPServerChecker.py b/jobs/TCPServerChecker.py
index 642e188..bdb914c 100755
--- a/jobs/TCPServerChecker.py
+++ b/jobs/TCPServerChecker.py
@@ -14,6 +14,7 @@ class TCPServerChecker(JobSpawner.JobSpawner):
class ServerChecker(JobBase.JobBase):
def __init__(self, config, ip, port, friendlyName, frequency, failureNotificationFrequency):
+ JobBase.JobBase.__init__(self, config, ip, port, friendlyName, frequency, failureNotificationFrequency)
self.config = config
self.ip = ip
self.port = port