Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit 2736fb5

Browse files
committed
Split pending job checking from queueing
Alter the pendingpatches table so that it only contains a timestamp and a patch_id that links to the id field of the patch table. All of the relevant data about a patch is in the patch table already and there is no need to replicate it in pendingpatches. Change check_pending() so that it searches the pendingjobs table and takes action on completed baselines and patchwork tests. Handle any aborted jobs properly without throwing exceptions. Signed-off-by: Major Hayden <[email protected]>
1 parent acc78d0 commit 2736fb5

File tree

4 files changed

+91
-96
lines changed

4 files changed

+91
-96
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ALTER TABLE pendingpatches RENAME TO pendingpatches_old;
2+
CREATE TABLE pendingpatches(
3+
id INTEGER PRIMARY KEY,
4+
patch_id INTEGER UNIQUE,
5+
timestamp INTEGER,
6+
FOREIGN KEY(patch_id) REFERENCES patch(id)
7+
);
8+
9+
INSERT INTO pendingpatches (patch_id, timestamp)
10+
SELECT id, timestamp FROM pendingpatches_old;
11+
12+
DROP TABLE pendingpatches_old;

sktm/__init__.py

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -336,50 +336,66 @@ def check_patchwork(self):
336336
series.get_patch_url_list())
337337

338338
def check_pending(self):
339-
for (pjt, bid, cpw) in self.pj:
340-
if self.jk.is_build_complete(self.jobname, bid):
341-
logging.info("job completed: jjid=%d; type=%d", bid, pjt)
342-
self.pj.remove((pjt, bid, cpw))
343-
if pjt == sktm.jtype.BASELINE:
344-
self.db.update_baseline(
345-
self.baserepo,
346-
self.jk.get_base_hash(self.jobname, bid),
347-
self.jk.get_base_commitdate(self.jobname, bid),
348-
self.jk.get_result(self.jobname, bid),
349-
bid
350-
)
351-
elif pjt == sktm.jtype.PATCHWORK:
352-
patches = list()
353-
bres = self.jk.get_result(self.jobname, bid)
354-
rurl = self.jk.get_result_url(self.jobname, bid)
355-
logging.info("result=%s", bres)
356-
logging.info("url=%s", rurl)
357-
basehash = self.jk.get_base_hash(self.jobname, bid)
358-
logging.info("basehash=%s", basehash)
359-
if bres == sktm.tresult.BASELINE_FAILURE:
360-
self.db.update_baseline(
361-
self.baserepo,
362-
basehash,
363-
self.jk.get_base_commitdate(self.jobname, bid),
364-
sktm.tresult.TEST_FAILURE,
365-
bid
366-
)
367-
368-
patch_url_list = self.jk.get_patchwork(self.jobname, bid)
369-
for patch_url in patch_url_list:
370-
patches.append(self.get_patch_info_from_url(cpw,
371-
patch_url))
372-
373-
if bres != sktm.tresult.BASELINE_FAILURE:
374-
self.db.commit_tested(patches)
375-
else:
376-
raise Exception("Unknown job type: %d" % pjt)
377-
378-
def wait_for_pending(self):
379-
self.check_pending()
380-
while self.pj:
381-
logging.debug("waiting for jobs to complete. %d remaining",
382-
len(self.pj))
383-
time.sleep(60)
384-
self.check_pending()
385-
logging.info("no more pending jobs")
339+
"""Check on jobs that were sent to Jenkins during the last sktm run."""
340+
# Get a list of pending Jenkins jobs
341+
pending_jobs = self.db.get_pending_jobs()
342+
343+
if not pending_jobs:
344+
logging.info("No pending jobs to check -- exiting")
345+
return
346+
347+
for pending_job in pending_jobs:
348+
pendingjob_id, job_name, build_id = pending_job
349+
logging.info("Checking job: %s (#%d)", job_name, build_id)
350+
351+
# Come back and check on the job later if it is still running.
352+
if not self.jk.is_build_complete(job_name, build_id):
353+
logging.info(
354+
"Job is still running: %s (#%d)", job_name, build_id
355+
)
356+
continue
357+
358+
# Get the build status and check to see if it was aborted.
359+
result = self.jk.get_build_status(job_name, build_id)
360+
if result == 'ABORTED':
361+
logging.info(
362+
"Test was aborted in Jenkins: %s (#%d)",
363+
job_name,
364+
build_id
365+
)
366+
# Remove the pending job and any associated patches.
367+
self.db.remove_pending_job(pendingjob_id)
368+
continue
369+
370+
# Get a list of pending patches associated with this job.
371+
pending_patches = self.db.get_patches_for_job(pendingjob_id)
372+
373+
# Was this a baseline test?
374+
if not pending_patches:
375+
logging.info(
376+
"Baseline test completed: %s (#%d) [%s]",
377+
job_name,
378+
build_id,
379+
result
380+
)
381+
# Update the database with the results of the baseline test.
382+
self.db.update_baseline(
383+
self.baserepo,
384+
self.jk.get_base_hash(job_name, build_id),
385+
self.jk.get_base_commitdate(job_name, build_id),
386+
self.jk.get_result(job_name, build_id),
387+
build_id
388+
)
389+
self.db.remove_pending_job(pendingjob_id)
390+
return
391+
392+
# If we made it this far, we are working on a patchwork test.
393+
logging.info(
394+
"Patchwork test completed: %s (#%d) [%s]",
395+
job_name,
396+
build_id,
397+
result
398+
)
399+
400+
# Clean up the list of pending patches.
401+
self.db.commit_tested([x[1] for x in pending_patches])

sktm/db.py

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ def __createdb(self, db):
6262
6363
CREATE TABLE pendingpatches(
6464
id INTEGER PRIMARY KEY,
65-
pdate TEXT,
66-
patchsource_id INTEGER,
65+
patch_id INTEGER UNIQUE,
6766
timestamp INTEGER,
68-
FOREIGN KEY(patchsource_id) REFERENCES patchsource(id)
67+
FOREIGN KEY(patch_id) REFERENCES patch(id)
6968
);
7069
7170
CREATE TABLE pendingjobs(
@@ -425,57 +424,36 @@ def __get_latest(self, baserepo):
425424

426425
return result[0]
427426

428-
def set_patchset_pending(self, baseurl, project_id, series_data):
429-
"""Add a patch to pendingpatches or update an existing entry.
430-
431-
Add each specified patch to the list of "pending" patches, with
432-
specifed patch date, for specified Patchwork base URL and project ID,
433-
and marked with current timestamp. Replace any previously added
434-
patches with the same ID (bug: should be "same ID, project ID and
435-
base URL").
427+
def set_patchset_pending(self, series_data):
428+
"""Add or update an entry to the pending patches table.
436429
437430
Args:
438-
baseurl: Base URL of the Patchwork instance the project ID and
439-
patch IDs belong to.
440-
project_id: ID of the Patchwork project the patch IDs belong to.
441-
series_data: List of info tuples for patches to add to the list,
442-
where each tuple contains the patch ID and a free-form
443-
patch date string.
431+
series_data: List of info tuple of patches to add to the pending
432+
patches list.
444433
445434
"""
446435
sourceid = self.__get_sourceid(baseurl, project_id)
447436
tstamp = int(time.time())
448437

449438
logging.debug("setting patches as pending: %s", series_data)
450-
self.cur.executemany('INSERT OR REPLACE INTO '
451-
'pendingpatches(id, pdate, patchsource_id, '
452-
'timestamp) '
453-
'VALUES(?, ?, ?, ?)',
454-
[(patch_id, patch_date, sourceid, tstamp) for
455-
(patch_id, patch_date) in series_data])
439+
self.cur.executemany(
440+
'INSERT OR REPLACE INTO pendingpatches '
441+
'(patch_id, timestamp) VALUES(?, ?)',
442+
[(patch_id, tstamp) for (patch_id, patch_date) in series_data])
456443
self.conn.commit()
457444

458-
def __unset_patchset_pending(self, baseurl, patch_id_list):
459-
"""Remove a patch from the list of pending patches.
460-
461-
Remove each specified patch from the list of "pending" patches, for
462-
the specified Patchwork base URL.
445+
def __unset_patchset_pending(self, patch_id_list):
446+
"""Remove patches from the list of pending patches.
463447
464448
Args:
465-
baseurl: Base URL of the Patchwork instance the patch IDs
466-
belong to.
467449
patch_id_list: List of IDs of patches to be removed from the list.
468450
469451
"""
470452
logging.debug("removing patches from pending list: %s", patch_id_list)
471453

472-
self.cur.executemany('DELETE FROM pendingpatches WHERE '
473-
'patchsource_id IN '
474-
'(SELECT DISTINCT id FROM patchsource WHERE '
475-
'baseurl = ?) '
476-
'AND id = ? ',
477-
[(baseurl, patch_id) for
478-
patch_id in patch_id_list])
454+
self.cur.executemany(
455+
'DELETE FROM pendingpatches WHERE patch_id = ?', [patches]
456+
)
479457
self.conn.commit()
480458

481459
def update_baseline(self, baserepo, commithash, commitdate,
@@ -521,13 +499,7 @@ def commit_tested(self, patches):
521499
patches: List of patches that were tested
522500
"""
523501
logging.debug("commit_tested: patches=%d", len(patches))
524-
self.commit_series(patches)
525-
526-
for (patch_id, patch_name, patch_url, baseurl, project_id,
527-
patch_date) in patches:
528-
# TODO: Can accumulate per-project list instead of doing it one by
529-
# one
530-
self.__unset_patchset_pending(baseurl, [patch_id])
502+
self.__unset_patchset_pending(patches)
531503

532504
def __commit_testrun(self, result, buildid):
533505
"""Add a test run to the database.

sktm/executable.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ def main():
143143
cfg.get("filter"), cfg.get("makeopts"))
144144

145145
args.func(sw, cfg)
146-
try:
147-
sw.wait_for_pending()
148-
except KeyboardInterrupt:
149-
logging.info("Quitting...")
150-
sw.cleanup()
151146

152147

153148
if __name__ == '__main__':

0 commit comments

Comments
 (0)