Merge ~andersson123/autopkgtest-cloud:ugj-check-running into autopkgtest-cloud:master

Proposed by Tim Andersson
Status: Merged
Merged at revision: 7f6587162a6be04b9244f8aa0989c16b40b5fca7
Proposed branch: ~andersson123/autopkgtest-cloud:ugj-check-running
Merge into: autopkgtest-cloud:master
Diff against target: 110 lines (+62/-2)
1 file modified
charms/focal/autopkgtest-web/webcontrol/update-github-jobs (+62/-2)
Reviewer Review Type Date Requested Status
Skia Approve
Review via email: mp+461823@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Skia (hyask) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/webcontrol/update-github-jobs b/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
2index c0f10fb..9aeb8e7 100755
3--- a/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
4+++ b/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
5@@ -6,6 +6,7 @@ import io
6 import json
7 import logging
8 import os
9+import pathlib
10 import sys
11 import tarfile
12 from datetime import datetime, timedelta
13@@ -14,6 +15,7 @@ import swiftclient
14 from request.submit import Submit
15
16 PENDING_DIR = "/run/autopkgtest_webcontrol/github-pending"
17+RUNNING_CACHE = "/run/amqp-status-collector/running.json"
18 SWIFT_CREDS_FILE = "/home/ubuntu/public-swift-creds"
19 MAX_DAY_DIFF = 30
20
21@@ -102,6 +104,37 @@ def finish_job(jobfile, params, code, log_url):
22 logging.debug("job %s finished!" % jobfile)
23
24
25+def is_job_running(params):
26+ job_match_me = (
27+ params["arch"],
28+ params["release"],
29+ params["build-git"],
30+ params["ppas"],
31+ params["env"],
32+ )
33+
34+ running_file = pathlib.Path(RUNNING_CACHE)
35+ running_json = json.loads(running_file.read_text())
36+ packages = running_json.keys()
37+ if params["package"] not in packages:
38+ return False
39+ running_jobs = running_json[params["package"]]
40+ for _, vals in running_jobs.items():
41+ for release, vars in vals.items():
42+ for arch, tests in vars.items():
43+ test_params = tests[0]
44+ this_test = (
45+ arch,
46+ release,
47+ test_params["build-git"],
48+ test_params["ppas"],
49+ test_params["env"],
50+ )
51+ if this_test == job_match_me:
52+ return True
53+ return False
54+
55+
56 def process_job(jobfile, swift_conn, ext_url):
57 try:
58 with open(jobfile) as f:
59@@ -110,6 +143,10 @@ def process_job(jobfile, swift_conn, ext_url):
60 except json.decoder.JSONDecodeError as e:
61 logging.error("couldn't read %s, skipping: %s", jobfile, e)
62 return
63+ # if the job is currently running, it indicates a re-trigger has occurred!
64+ if is_job_running(params):
65+ logging.debug("job %s is currently running, skipping.")
66+ return
67
68 logging.debug(
69 "\n\n--------------------\nprocessing job %s:\n %s",
70@@ -128,6 +165,7 @@ def process_job(jobfile, swift_conn, ext_url):
71
72 _, object_list = swift_conn.get_container(container, full_listing=True)
73
74+ result_for_finishing_job = {}
75 for obj in object_list:
76 if "result.tar" in obj["name"]:
77 last_modified = obj["last_modified"].split(".")[0]
78@@ -145,8 +183,30 @@ def process_job(jobfile, swift_conn, ext_url):
79 log_url = "/".join([ext_url, container, obj["name"]]).replace(
80 "result.tar", "log.gz"
81 )
82- finish_job(jobfile, params, code, log_url)
83- return
84+ if not result_for_finishing_job:
85+ result_for_finishing_job = {
86+ "jobfile": jobfile,
87+ "params": params,
88+ "code": code,
89+ "log_url": log_url,
90+ "last_modified": obj_time_fmt.timestamp(),
91+ }
92+ else:
93+ # this result is more recent, indicating a manual re-trigger
94+ if (
95+ obj_time_fmt.timestamp()
96+ > result_for_finishing_job["last_modified"]
97+ ):
98+ result_for_finishing_job = {
99+ "jobfile": jobfile,
100+ "params": params,
101+ "code": code,
102+ "log_url": log_url,
103+ "last_modified": obj_time_fmt.timestamp(),
104+ }
105+ if result_for_finishing_job:
106+ del result_for_finishing_job["last_modified"]
107+ finish_job(**result_for_finishing_job)
108
109
110 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches