Package linspector :: Package lib :: Package core :: Module job
[hide private]
[frames] | no frames]

Source Code for Module linspector.lib.core.job

 1  """ 
 2  This is what job_function needs as parameter for each job to successfully 
 3  execute. 
 4  """ 
 5   
 6  from command import Command 
 7   
 8   
9 -def generateId():
10 i = 0 11 while True: 12 yield i 13 i += 1
14 15
16 -class JobInfo:
17 - def __init__(self, hostgroupname, members, hosts, hostServices, threshold, parent=None):
18 self.members = members 19 self.hosts = hosts 20 self.hostServices = hostServices 21 self.threshold = threshold 22 self.parent = parent 23 self.name = generateId() 24 #self.name = hostgroupname + str([str("_" + s.service.name ) for s in hostServices]) 25 self.jobs = []
26
27 - def __str__(self):
28 return "JobInfo " + str(self.name)
29
30 - def setLogger(self, log):
31 self.log = log
32
33 - def appendJob(self, job):
34 self.jobs.append(job)
35
36 - def getNextExecutionTime(self):
37 nextExecution = None 38 for job in self.jobs: 39 jobExec = job.trigger.get_next_fire_time() 40 if nextExecution is None or nextExecution > jobExec: 41 nextExecution = jobExec 42 return nextExecution
43
44 - def handleCall(self):
45 self.log.d("handle call") 46 self.log.d(self.hostServices) 47 try: 48 49 for hs in self.hostServices: 50 self.log.d(str(hs)) 51 cmd = Command(hs.service.command, self.log) 52 cmd.call() 53 self.log.d(cmd.getAllOutput()) 54 except Exception: 55 self.log.d(Exception)
56