Query all jobs once
Instead of doing an individual api call each time, to check if a job exists, do an initial jenkins get_jobs() call on init, and use that list as a cache, to speed up job queries. If a job is not found in cache, we still will be querying jenkins directly as a fallback. Change-Id: Ie3eff875f4d832a42c9e38478f62055bc135a7e0
This commit is contained in:
parent
5be7b768de
commit
6c6370bbff
@ -140,6 +140,22 @@ class CacheStorage(object):
|
||||
class Jenkins(object):
|
||||
def __init__(self, url, user, password):
|
||||
self.jenkins = jenkins.Jenkins(url, user, password)
|
||||
self._jobs = None
|
||||
self._job_list = None
|
||||
|
||||
@property
|
||||
def jobs(self):
|
||||
if self._jobs is None:
|
||||
# populate jobs
|
||||
self._jobs = self.jenkins.get_jobs()
|
||||
|
||||
return self._jobs
|
||||
|
||||
@property
|
||||
def job_list(self):
|
||||
if self._job_list is None:
|
||||
self._job_list = set(job['name'] for job in self.jobs)
|
||||
return self._job_list
|
||||
|
||||
def update_job(self, job_name, xml):
|
||||
if self.is_job(job_name):
|
||||
@ -150,6 +166,11 @@ class Jenkins(object):
|
||||
self.jenkins.create_job(job_name, xml)
|
||||
|
||||
def is_job(self, job_name):
|
||||
# first use cache
|
||||
if job_name in self.job_list:
|
||||
return True
|
||||
|
||||
# if not exists, use jenkins
|
||||
return self.jenkins.job_exists(job_name)
|
||||
|
||||
def get_job_md5(self, job_name):
|
||||
@ -181,8 +202,11 @@ class Jenkins(object):
|
||||
|
||||
return plugins_list
|
||||
|
||||
def get_jobs(self):
|
||||
return self.jenkins.get_jobs()
|
||||
def get_jobs(self, cache=True):
|
||||
if not cache:
|
||||
self._jobs = None
|
||||
self._job_list = None
|
||||
return self.jobs
|
||||
|
||||
def is_managed(self, job_name):
|
||||
xml = self.jenkins.get_job_config(job_name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user