[IMP] runbot: color "pending" tag accordingly to some limits

Closes: #22
This commit is contained in:
Christophe Simonis 2018-06-07 11:28:27 +02:00 committed by Christophe Monniez
parent b1f155c1a2
commit 806ae08460
3 changed files with 16 additions and 4 deletions

View File

@ -37,6 +37,14 @@ class Runbot(http.Controller):
'revdep_build_ids': sorted(build.revdep_build_ids, key=lambda x: x.repo_id.name), 'revdep_build_ids': sorted(build.revdep_build_ids, key=lambda x: x.repo_id.name),
} }
def _pending(self):
ICP = request.env['ir.config_parameter'].sudo().get_param
warn = int(ICP('runbot.pending.warning', 5))
crit = int(ICP('runbot.pending.critical', 12))
count = request.env['runbot.build'].search_count([('state', '=', 'pending')])
level = ['info', 'warning', 'danger'][int(count > warn) + int(count > crit)]
return count, level
@http.route(['/runbot', '/runbot/repo/<model("runbot.repo"):repo>'], website=True, auth='public', type='http') @http.route(['/runbot', '/runbot/repo/<model("runbot.repo"):repo>'], website=True, auth='public', type='http')
def repo(self, repo=None, search='', limit='100', refresh='', **kwargs): def repo(self, repo=None, search='', limit='100', refresh='', **kwargs):
branch_obj = request.env['runbot.branch'] branch_obj = request.env['runbot.branch']
@ -48,11 +56,13 @@ class Runbot(http.Controller):
if not repo and repos: if not repo and repos:
repo = repos[0].id repo = repos[0].id
pending = self._pending()
context = { context = {
'repos': repos.ids, 'repos': repos.ids,
'repo': repo, 'repo': repo,
'host_stats': [], 'host_stats': [],
'pending_total': build_obj.search_count([('state', '=', 'pending')]), 'pending_total': pending[0],
'pending_level': pending[1],
'limit': limit, 'limit': limit,
'search': search, 'search': search,
'refresh': refresh, 'refresh': refresh,
@ -244,10 +254,12 @@ class Runbot(http.Controller):
builds = RB.browse(map(operator.itemgetter(0), cr.fetchall())) builds = RB.browse(map(operator.itemgetter(0), cr.fetchall()))
count = RB.search_count count = RB.search_count
pending = self._pending()
qctx = { qctx = {
'refresh': refresh, 'refresh': refresh,
'host_stats': [], 'host_stats': [],
'pending_total': count([('state', '=', 'pending')]), 'pending_total': pending[0],
'pending_level': pending[1],
} }
repos_values = qctx['repo_dict'] = OrderedDict() repos_values = qctx['repo_dict'] = OrderedDict()

View File

@ -28,7 +28,7 @@
<t t-esc="hs['host']"/>: <t t-esc="hs['testing']"/> testing, <t t-esc="hs['running']"/> running <t t-esc="hs['host']"/>: <t t-esc="hs['testing']"/> testing, <t t-esc="hs['running']"/> running
</span>&amp;nbsp; </span>&amp;nbsp;
</t> </t>
<span class="label label-info">Pending: <t t-esc="pending_total"/></span> <span t-attf-class="label label-{{pending_level}}">Pending: <t t-esc="pending_total"/></span>
</p> </p>
</div> </div>
<t t-foreach="repo_dict.values()" t-as="repo"> <t t-foreach="repo_dict.values()" t-as="repo">

View File

@ -97,7 +97,7 @@
<t t-esc="hs['host']"/>: <t t-esc="hs['testing']"/> testing, <t t-esc="hs['running']"/> running <t t-esc="hs['host']"/>: <t t-esc="hs['testing']"/> testing, <t t-esc="hs['running']"/> running
</span>&amp;nbsp; </span>&amp;nbsp;
</t> </t>
<span class="label label-info">Pending: <t t-esc="pending_total"/></span> <span t-attf-class="label label-{{pending_level}}">Pending: <t t-esc="pending_total"/></span>
</p> </p>
</div> </div>
</nav> </nav>