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

Side by Side Diff: appengine/findit/handlers/try_job_dashboard.py

Issue 1949763002: [Findit] Adding try job dashboard (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Addressing nits Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « appengine/findit/handlers/test/try_job_dashboard_test.py ('k') | appengine/findit/main.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 from datetime import datetime
5 from datetime import time
6 from datetime import timedelta
7
8 from common.base_handler import BaseHandler
9 from common.base_handler import Permission
10 from model.wf_try_job_data import WfTryJobData
11
12
13 # TODO(lijeffrey): Refactor formatting functions into a separate module that
14 # can be shared across Findit.
15 def _RemoveMicrosecondsFromDelta(delta):
16 """Returns a timedelta object without microseconds based on delta."""
17 return delta - timedelta(microseconds=delta.microseconds)
18
19
20 def _FormatTimedelta(delta):
21 if not delta:
22 return None
23 hours, remainder = divmod(delta.seconds, 3600)
24 minutes, seconds = divmod(remainder, 60)
25 return '%02d:%02d:%02d' % (hours, minutes, seconds)
26
27
28 def _FormatDatetime(date):
29 if not date:
30 return None
31 else:
32 return date.strftime('%Y-%m-%d %H:%M:%S UTC')
33
34
35 class TryJobDashboard(BaseHandler):
36 PERMISSION_LEVEL = Permission.ANYONE
37
38 def HandleGet(self):
39 """Shows a list of Findit try job results and statuses in an HTML page."""
40 midnight_today = datetime.combine(datetime.utcnow(), time.min)
41 midnight_yesterday = midnight_today - timedelta(days=1)
42 midnight_tomorrow = midnight_today + timedelta(days=1)
43
44 start = self.request.get('start_date')
45 end = self.request.get('end_date')
46 start_date = (datetime.strptime(start, '%Y-%m-%d') if start else
47 midnight_yesterday)
48 end_date = (datetime.strptime(end, '%Y-%m-%d') if end else
49 midnight_tomorrow)
50
51 if start or not end: # pragma: no branch
52 # If a start date is specified, get everything since then.
53 try_job_query = WfTryJobData.query(
54 WfTryJobData.request_time >= start_date,
55 WfTryJobData.request_time < end_date)
56 else: # pragma: no cover
57 # If no start date specified, then get everything up until end_date.
58 start_date = None
59 try_job_query = WfTryJobData.query(
60 WfTryJobData.request_time < end_date)
61
62 try_job_data_list = try_job_query.fetch()
63 try_jobs_in_progress = []
64 try_jobs_with_error = []
65 successfully_completed_try_jobs = []
66
67 for try_job_data in try_job_data_list:
68 try_job_display_data = {
69 'master_name': try_job_data.master_name,
70 'builder_name': try_job_data.builder_name,
71 'build_number': try_job_data.build_number,
72 'try_job_type': try_job_data.try_job_type,
73 'start_time': _FormatDatetime(try_job_data.start_time),
74 'request_time': _FormatDatetime(try_job_data.request_time),
75 'try_job_url': try_job_data.try_job_url
76 }
77
78 if not try_job_data.end_time and not try_job_data.error:
79 try_job_display_data['elapsed_time'] = (
80 _FormatTimedelta(datetime.utcnow() - try_job_data.request_time) if
81 try_job_data.request_time else None)
82
83 try_job_display_data['status'] = (
84 'running' if try_job_data.start_time else 'pending')
85 try_jobs_in_progress.append(try_job_display_data)
86 elif try_job_data.error:
87 try_job_display_data['error'] = try_job_data.error['message']
88 # It is possible end_time is not available if the error was timeout.
89 try_job_display_data['end_time'] = _FormatDatetime(
90 try_job_data.end_time)
91 try_jobs_with_error.append(try_job_display_data)
92 else:
93 try_job_display_data['culprit_found'] = bool(try_job_data.culprits)
94 try_job_display_data['end_time'] = (
95 _FormatDatetime(try_job_data.end_time))
96 successfully_completed_try_jobs.append(try_job_display_data)
97
98 data = {
99 'start_date': _FormatDatetime(start_date),
100 'end_date': _FormatDatetime(end_date),
101 'try_jobs_in_progress': try_jobs_in_progress,
102 'try_jobs_with_error': try_jobs_with_error,
103 'successfully_completed_try_jobs': successfully_completed_try_jobs
104 }
105
106 return {
107 'template': 'try_job_dashboard.html',
108 'data': data
109 }
OLDNEW
« no previous file with comments | « appengine/findit/handlers/test/try_job_dashboard_test.py ('k') | appengine/findit/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698