linspector-old/lib/core/job.py

63 lines
1.5 KiB
Python
Raw Normal View History

2013-05-16 23:03:00 +02:00
"""
2013-05-27 20:27:57 +02:00
This is what job_function needs as parameter for each job to successfully
2013-05-16 23:03:00 +02:00
execute.
"""
2013-07-02 23:30:31 +02:00
from datetime import datetime
2013-05-30 04:20:35 +02:00
2013-05-29 22:52:54 +02:00
def generateId():
2013-05-30 04:20:35 +02:00
i = 0
2013-05-29 22:52:54 +02:00
while True:
2013-05-30 04:20:35 +02:00
yield i
i += 1
2013-07-02 23:30:31 +02:00
class Job:
2013-06-21 02:20:58 +02:00
def __init__(self, service):
self.service = service
2013-07-02 23:30:31 +02:00
self.jobInfos = []
self.hostThreshold = {}
for host in service.get_hostgroup().get_hosts():
self.hostThreshold[host] = service.get_threshold()
2013-05-27 01:44:28 +02:00
2013-07-02 23:30:31 +02:00
2013-05-27 01:44:28 +02:00
def __str__(self):
2013-07-02 23:30:31 +02:00
return str(self.__dict__)
2013-06-21 02:20:58 +02:00
def set_logger(self, log):
self.log = log
2013-06-21 02:20:58 +02:00
def set_job(self, job):
self.job = job
def handle_call(self):
2013-05-29 22:52:54 +02:00
self.log.d("handle call")
2013-06-21 02:20:58 +02:00
self.log.d(self.service)
2013-07-02 00:19:20 +02:00
2013-07-02 23:30:31 +02:00
for host in self.service.get_hostgroup().get_hosts():
try:
jobInfo = JobInfo(host, self.service)
result = self.service._execute(host)
jobInfo.set_result(result)
jobInfo.set_successfull(self.service.was_execution_successful())
jobInfo.set_execution_end()
except Exception, e:
self.log.d(e)
class JobInfo:
def __init__(self, host, service):
self.id = generateId()
self.host = host
self.service = service
self.executionBegin = datetime.now()
def set_result(self, result):
self.result = result
def set_execution_end(self):
self.executionEnd = datetime.now()
def set_execution_successful(self, successful):
self.executionSuccess = successful