-
Notifications
You must be signed in to change notification settings - Fork 0
/
probe.py
39 lines (32 loc) · 1.41 KB
/
probe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from src.jenkins import Jenkins
from src.job_repository import JobRepository
from datetime import datetime
class Probe(Jenkins, JobRepository):
def checkJobs(self):
try:
jobs = Jenkins.listJobs(self)
job_title = []
job_status = []
checked_at = []
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for job in jobs:
#edge case -1
#newly created jobs that are yet to build
if job['lastBuild'] is None:
job['lastBuild'] = {'result': 'PENDING'}
#edge- case -2
#jobs whose execution was terminate due user terminating it manually
if job['lastBuild']['result'] is None:
job['lastBuild']['result'] = 'TERMINATED'
print 'probing job: '+job['displayName']+ ' having status: '+job['lastBuild']['result']+ ' ....'
job_title.append(job['displayName'])
job_status.append(job['lastBuild']['result'])
checked_at.append(current_time)
print 'Saving probe results to database....'
db_data = zip(job_title, job_status, checked_at)
JobRepository.insert(self, db_data)
print "Finished probing jobs"
except Exception as e:
print 'Opps, something went wrong: ', e
probe = Probe()
probe.checkJobs()