blob: 123ed1a1de10dacaea07f95419b840fb74f98164 [file] [log] [blame]
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from datetime import datetime
from datetime import time
from datetime import timedelta
from google.appengine.ext import ndb
from common.waterfall import failure_type
from gae_libs.handlers.base_handler import BaseHandler
from gae_libs.handlers.base_handler import Permission
from libs import time_util
from model.wf_analysis import WfAnalysis
_COUNT = 500
def _GetStartEndDates(start, end, midnight_today):
midnight_yesterday = midnight_today - timedelta(days=1)
midnight_tomorrow = midnight_today + timedelta(days=1)
if not start and not end:
# If neither start nor end specified, get everything since yesterday.
return midnight_yesterday, midnight_tomorrow
elif not start and end:
# If only end is specified, get everything up until then.
return None, midnight_tomorrow
elif start and not end:
# If only start is specified, get everything since then.
return datetime.strptime(start, '%Y-%m-%d'), midnight_tomorrow
# Both start and end are specified, get everything in between.
return (datetime.strptime(start, '%Y-%m-%d'), datetime.strptime(
end, '%Y-%m-%d'))
def _Serialize(analysis):
return {
class PipelineErrorsDashboard(BaseHandler):
def HandleGet(self):
"""Lists WfAnalysis entities detected to have been aborted."""
midnight_today = datetime.combine(time_util.GetUTCNow(), time.min)
start = self.request.get('start_date')
end = self.request.get('end_date')
start_date, end_date = _GetStartEndDates(start, end, midnight_today)
analyses = WfAnalysis.query(
ndb.AND(WfAnalysis.build_start_time >= start_date,
WfAnalysis.build_start_time < end_date, WfAnalysis.aborted ==
analyses_data = []
for analysis in analyses:
data = {
'start_date': time_util.FormatDatetime(start_date),
'end_date': time_util.FormatDatetime(end_date),
'analyses': analyses_data,
return {'template': 'pipeline_errors_dashboard.html', 'data': data}