[ADD] runbot: new /runbot/glances route

Allow to have a glances on sticky builds status.

Closes: #28
This commit is contained in:
Christophe Simonis 2018-06-25 09:26:35 +02:00 committed by Christophe Monniez
parent 52cdd9fd27
commit e815571d14
2 changed files with 75 additions and 0 deletions

View File

@ -291,3 +291,39 @@ class Runbot(http.Controller):
})
return request.render("runbot.sticky-dashboard", qctx)
@http.route('/runbot/glances', type='http', auth='public', website=True)
def glances(self, refresh=None):
repos = request.env['runbot.repo'].search([]) # respect record rules
query = """
SELECT split_part(r.name, ':', 2),
br.branch_name,
(array_agg(coalesce(du.result, bu.result) order by bu.id desc))[1]
FROM runbot_build bu
JOIN runbot_branch br on (br.id = bu.branch_id)
JOIN runbot_repo r on (r.id = br.repo_id)
LEFT JOIN runbot_build du on (du.id = bu.duplicate_id and bu.state='duplicate')
WHERE br.sticky
AND br.repo_id in %s
AND (
bu.state in ('running', 'done') or
(bu.state='duplicate' and du.state in ('running', 'done'))
)
AND coalesce(du.result, bu.result) not in ('skipped', 'manually_killed')
GROUP BY 1,2,r.sequence,br.id
ORDER BY r.sequence, (br.branch_name='master'), br.id
"""
cr = request.env.cr
cr.execute(query, [tuple(repos.ids)])
ctx = OrderedDict()
for row in cr.fetchall():
ctx.setdefault(row[0], []).append(row[1:])
pending = self._pending()
qctx = {
'refresh': refresh,
'pending_total': pending[0],
'pending_level': pending[1],
'data': ctx,
}
return request.render("runbot.glances", qctx)

View File

@ -76,5 +76,44 @@
</div>
</t>
</template>
<template id="runbot.glances">
<t t-call='website.layout'>
<t t-set="head">
<t t-if="refresh">
<meta http-equiv="refresh" t-att-content="refresh"/>
</t>
<style>
.label-killed {
background-color: #aaa;
}
h4 {
padding: 3px 0;
border-bottom: 1px solid grey;
}
.r-mb02 { margin-bottom: 0.2em; }
</style>
</t>
<div class="container-fluid">
<div class="row">
<div class='col-md-12'>
<div>
<span t-attf-class="label label-{{pending_level}}">Pending: <t t-esc="pending_total"/></span>
</div>
<t t-foreach="data.keys()" t-as="repo">
<h4><t t-esc="repo"/>
</h4>
<t t-foreach="data[repo]" t-as="br">
<t t-if="br[1] == 'ko'"><t t-set="klass">danger</t></t>
<t t-if="br[1] == 'warn'"><t t-set="klass">warning</t></t>
<t t-if="br[1] == 'ok'"><t t-set="klass">success</t></t>
<t t-if="br[1] == 'killed'"><t t-set="klass">killed</t></t>
<span t-attf-class="label label-{{klass}}"><t t-esc="br[0]"/></span>
</t>
</t>
</div>
</div>
</div>
</t>
</template>
</data>
</odoo>