Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1205)

Unified Diff: git_cl.py

Issue 2438433004: git cl try-results: add --wait-till-finished option. (Closed)
Patch Set: Tests. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index 18dc963407d46321b7f77937af2f9ed1de3fcfeb..53cf39fb6dbbee5988bbf06217b5231a9fc04fab 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -154,6 +154,12 @@ def time_sleep(seconds):
return time.sleep(seconds)
+def time_time():
+ # Use this so that it can be mocked in tests without interfering with python
+ # system machinery.
+ import time # Local import to discourage others from importing time globally.
+ return time.time()
+
def ask_for_data(prompt):
try:
return raw_input(prompt)
@@ -458,6 +464,11 @@ def fetch_try_jobs(auth_config, changelist, buildbucket_host,
return builds
+def _count_unfinished_tryjobs(jobs):
+ """Returns number of unfinished jobs from fetch_try_jobs result."""
+ return sum(b['status'] != 'COMPLETED' for b in jobs.itervalues())
Sergiy Byelozyorov 2016/10/19 15:41:13 perhaps len(b for b in jobs.itervalues() if b['s
+
+
def print_try_jobs(options, builds):
"""Prints nicely result of fetch_try_jobs."""
if not builds:
@@ -4902,6 +4913,11 @@ def CMDtry_results(parser, args):
help='Host of buildbucket. The default host is %default.')
group.add_option(
'--json', help='Path of JSON output file to write try job results to.')
+ group.add_option(
+ '-w', '--wait-till-finished', action='store_true', default=False,
+ help='Keep checking buildbucket until either all jobs finish. '
Michael Achenbach 2016/10/20 09:40:35 nit: remove "either"?
+ 'If after 1 hour jobs are still running, aborts and returns error '
+ 'code 3.')
parser.add_option_group(group)
auth.add_auth_options(parser)
options, args = parser.parse_args(args)
@@ -4929,15 +4945,32 @@ def CMDtry_results(parser, args):
'By default, git cl try-results uses the latest patchset from '
'codereview, continuing to use patchset %s.\n' %
(patchset, cl.GetPatchset(), patchset))
- try:
- jobs = fetch_try_jobs(auth_config, cl, options.buildbucket_host, patchset)
- except BuildbucketResponseException as ex:
- print('Buildbucket error: %s' % ex)
- return 1
- if options.json:
- write_try_results_json(options.json, jobs)
- else:
- print_try_jobs(options, jobs)
+
+ start_time = time_time()
+ while True:
+ try:
+ jobs = fetch_try_jobs(auth_config, cl, options.buildbucket_host, patchset)
+ except BuildbucketResponseException as ex:
+ print('Buildbucket error: %s' % ex)
+ return 1
+ if options.json:
+ write_try_results_json(options.json, jobs)
Michael Achenbach 2016/10/20 09:40:35 Does this need to write the json in the loop? How
+ else:
+ print_try_jobs(options, jobs)
+ if not options.wait_till_finished:
+ return 0
Sergiy Byelozyorov 2016/10/19 15:41:13 Please "break", so that if someone chooses to add
+
+ # Only if --wait-till-finished is specified.
+ unfinished = _count_unfinished_tryjobs(jobs)
+ if not unfinished:
+ return 0
Sergiy Byelozyorov 2016/10/19 15:41:13 ditto
+ passed = time_time() - start_time
+ print('After %.0f seconds waiting, %d jobs still running\n\n' %
Sergiy Byelozyorov 2016/10/19 15:41:13 Juse use %d instead of %.0f. It will round it to t
+ (passed, unfinished))
+ if passed > 3600:
Michael Achenbach 2016/10/20 09:40:35 Do you need a limit at all? Is this tool supposed
Sergiy Byelozyorov 2016/10/20 11:44:43 IMHO, this is useful to prevent users forgetting t
+ print('Ran for too long, aborting now.')
+ return 3
+ time_sleep(10) # Limit unnecessary load on buildbucket.
Sergiy Byelozyorov 2016/10/19 15:41:13 If the option becomes widely popular, we may have
return 0
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698