Pipeline pages: list, pipeline and run views, live updates, permissions in one place
This commit is contained in:
1 parent
d4d8c28c20
commit
644756b965
6 files changed
+796
No files matched your search
@@ -0,0 +1,383 @@
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# OpenBench is a chess engine testing framework authored by Andrew Grant. #
|
||||
# <https://github.com/AndyGrant/OpenBench> <andrew@grantnet.us> #
|
||||
# #
|
||||
# OpenBench is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# OpenBench is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
|
||||
# The Pipeline pages: a list, the page of one Pipeline, and the page of one run.
|
||||
#
|
||||
# Who may do what, decided in one place ( can_manage ) and nowhere else:
|
||||
# - Anybody with an enabled account may look at Pipelines and their runs
|
||||
# - Only the author of a Pipeline, or an Approver, may start, pause, resume,
|
||||
# or delete it, or cancel one of its runs
|
||||
#
|
||||
# Everything that changes something is a POST, which Django checks the CSRF token
|
||||
# of, and takes no input from the request at all except which object it is for.
|
||||
# Every decision, allowed or refused, leaves an event behind.
|
||||
|
||||
import OpenBench.pipeline_graph as graphs
|
||||
import OpenBench.pipeline_layout as drawing
|
||||
import OpenBench.pipelines
|
||||
import OpenBench.views
|
||||
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from OpenBench.models import LogEvent, Pipeline, PipelineRun, Profile, StepRun, Test
|
||||
|
||||
STATUS_LABELS = {
|
||||
'QUEUED' : 'Waiting', 'LAUNCHING' : 'Starting', 'RUNNING' : 'Running',
|
||||
'PASSED' : 'Passed', 'FAILED' : 'Failed', 'STOPPED' : 'Stopped',
|
||||
'ERROR' : 'Could not start', 'COMPLETED' : 'Finished', 'CANCELLED' : 'Cancelled',
|
||||
}
|
||||
|
||||
STATUS_BADGES = {
|
||||
'QUEUED' : 'badge-muted', 'LAUNCHING' : 'badge-muted', 'RUNNING' : 'badge-info',
|
||||
'PASSED' : 'badge-ok', 'FAILED' : 'badge-bad', 'STOPPED' : 'badge-warn',
|
||||
'ERROR' : 'badge-bad', 'COMPLETED' : 'badge-ok', 'CANCELLED' : 'badge-warn',
|
||||
}
|
||||
|
||||
WORKLOAD_PATHS = { 'TEST' : 'test', 'TUNE' : 'tune', 'DATAGEN' : 'datagen' }
|
||||
|
||||
WHEN = {
|
||||
'passed' : 'it passes', 'failed' : 'it fails',
|
||||
'stopped' : 'it is stopped', 'any' : 'it ends',
|
||||
}
|
||||
|
||||
KIND_LABELS = { 'TEST' : 'Test', 'TUNE' : 'Tune', 'DATAGEN' : 'Datagen' }
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# PERMISSIONS #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
def viewer(request):
|
||||
|
||||
""" The Profile of whoever is asking, if they are logged in and enabled """
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
return None
|
||||
|
||||
profile = Profile.objects.select_related('user').filter(user=request.user).first()
|
||||
return profile if profile and profile.enabled else None
|
||||
|
||||
def can_manage(profile, pipeline):
|
||||
|
||||
""" The one rule for changing a Pipeline or its runs. Closed by default """
|
||||
|
||||
if profile is None or not profile.enabled:
|
||||
return False
|
||||
|
||||
return bool(profile.approver) or profile.user.username == pipeline.author
|
||||
|
||||
def _audit(username, summary):
|
||||
LogEvent.objects.create(author=username, summary=summary[:128], log_file='', test_id=0)
|
||||
|
||||
def _turn_away(request, profile, pipeline_id=None, action=''):
|
||||
|
||||
""" Anonymous visitors go to log in. People who are logged in, but not
|
||||
allowed, are told so, and it is written down. """
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
return OpenBench.views.redirect(request, '/login/', error=OpenBench.views.ERROR_MESSAGES['requires_login'])
|
||||
|
||||
if profile is None:
|
||||
return OpenBench.views.redirect(request, '/index/', error=OpenBench.views.ERROR_MESSAGES['disabled'])
|
||||
|
||||
if pipeline_id is not None:
|
||||
_audit(profile.user.username, 'PIPELINE #%d %s REFUSED' % (pipeline_id, action.upper()))
|
||||
|
||||
return OpenBench.views.redirect(request, '/pipelines/', error='Only the author of a pipeline, or an approver, can do that')
|
||||
|
||||
def _missing(request):
|
||||
return OpenBench.views.redirect(request, '/pipelines/', error='That pipeline does not exist, or was deleted')
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# PRESENTING #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
def _status(status):
|
||||
return { 'code' : status, 'label' : STATUS_LABELS.get(status, status.title()), 'badge' : STATUS_BADGES.get(status, 'badge-muted') }
|
||||
|
||||
def _step_name(graph, step_key):
|
||||
return (graph.get('steps', {}).get(step_key) or {}).get('name') or step_key
|
||||
|
||||
def _leads(graph, step_key):
|
||||
|
||||
""" What a step leads to, in plain sentences """
|
||||
|
||||
sentences = []
|
||||
|
||||
for edge in graph.get('edges', []):
|
||||
|
||||
if edge['from'] != step_key:
|
||||
continue
|
||||
|
||||
if edge['to'] is None:
|
||||
what = 'the pipeline ends'
|
||||
else:
|
||||
what = 'start %s' % (_step_name(graph, edge['to']))
|
||||
changes = len(edge.get('set') or {})
|
||||
if changes:
|
||||
what += ' with %d setting%s changed' % (changes, '' if changes == 1 else 's')
|
||||
|
||||
sentences.append('If %s, %s' % (WHEN.get(edge['on'], 'it ends'), what))
|
||||
|
||||
return sentences
|
||||
|
||||
def _describe_steps(graph):
|
||||
|
||||
rows = []
|
||||
|
||||
for step_key, step in graph['steps'].items():
|
||||
what, speed = drawing.step_summary(step)
|
||||
rows.append({
|
||||
'key' : step_key, 'name' : step.get('name') or step_key,
|
||||
'kind' : KIND_LABELS.get(step.get('kind'), step.get('kind')),
|
||||
'what' : what, 'speed' : speed,
|
||||
'leads' : _leads(graph, step_key),
|
||||
'start' : step_key == graph.get('start'),
|
||||
})
|
||||
|
||||
return rows
|
||||
|
||||
def _last_runs(pipelines):
|
||||
|
||||
latest = {}
|
||||
for run in PipelineRun.objects.filter(pipeline__in=pipelines).order_by('-id'):
|
||||
latest.setdefault(run.pipeline_id, run)
|
||||
return latest
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# PAGES #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
def pipelines(request):
|
||||
|
||||
profile = viewer(request)
|
||||
if profile is None:
|
||||
return _turn_away(request, profile)
|
||||
|
||||
listed = list(Pipeline.objects.filter(deleted=False).order_by('-updated'))
|
||||
latest = _last_runs(listed)
|
||||
|
||||
rows = []
|
||||
for pipeline in listed:
|
||||
|
||||
run = latest.get(pipeline.id)
|
||||
|
||||
if not pipeline.enabled:
|
||||
state = { 'code' : 'PAUSED', 'label' : 'Paused', 'badge' : 'badge-warn' }
|
||||
elif run is not None:
|
||||
state = _status(run.status)
|
||||
else:
|
||||
state = { 'code' : 'NEW', 'label' : 'Never run', 'badge' : 'badge-muted' }
|
||||
|
||||
rows.append({
|
||||
'pipeline' : pipeline, 'run' : run, 'state' : state,
|
||||
'steps' : len((pipeline.graph or {}).get('steps', {})),
|
||||
})
|
||||
|
||||
data = {
|
||||
'rows' : rows,
|
||||
'running' : PipelineRun.objects.filter(status='RUNNING', pipeline__deleted=False).count(),
|
||||
'paused' : sum(1 for row in rows if not row['pipeline'].enabled),
|
||||
'total' : len(rows),
|
||||
}
|
||||
|
||||
return OpenBench.views.render(request, 'pipelines.html', data)
|
||||
|
||||
def pipeline(request, id):
|
||||
|
||||
profile = viewer(request)
|
||||
if profile is None:
|
||||
return _turn_away(request, profile)
|
||||
|
||||
found = Pipeline.objects.filter(id=id, deleted=False).first()
|
||||
if found is None:
|
||||
return _missing(request)
|
||||
|
||||
issues = graphs.validate_graph(found.graph)
|
||||
usable = not graphs.has_errors(issues) # A graph damaged behind our back is shown as damaged, not drawn
|
||||
graph = found.graph if usable else None
|
||||
names = { key : (step.get('name') or key) for key, step in graph['steps'].items() } if usable else {}
|
||||
|
||||
runs = list(PipelineRun.objects.filter(pipeline=found).order_by('-id')[:20])
|
||||
for run in runs:
|
||||
run.state = _status(run.status)
|
||||
|
||||
data = {
|
||||
'pipeline' : found,
|
||||
'can_manage' : can_manage(profile, found),
|
||||
'svg' : drawing.render_svg(graph) if usable else '',
|
||||
'steps' : _describe_steps(graph) if usable else [],
|
||||
'usable' : usable,
|
||||
'issues' : [dict(i, name=names.get(i['step'], i['step'])) for i in issues],
|
||||
'runs' : runs,
|
||||
'running' : next((run for run in runs if run.status == 'RUNNING'), None),
|
||||
}
|
||||
|
||||
return OpenBench.views.render(request, 'pipeline.html', data)
|
||||
|
||||
def pipeline_run(request, run_id):
|
||||
|
||||
profile = viewer(request)
|
||||
if profile is None:
|
||||
return _turn_away(request, profile)
|
||||
|
||||
run = PipelineRun.objects.select_related('pipeline').filter(id=run_id).first()
|
||||
if run is None:
|
||||
return _missing(request)
|
||||
|
||||
graph = run.graph
|
||||
steps = list(StepRun.objects.filter(run=run).order_by('id'))
|
||||
|
||||
approved = {
|
||||
row['id'] : row['approved']
|
||||
for row in Test.objects.filter(id__in=[s.test_id for s in steps if s.test_id]).values('id', 'approved')
|
||||
}
|
||||
|
||||
states, hops, rows, keys = {}, [], [], {}
|
||||
for step in steps:
|
||||
|
||||
keys[step.id] = step.step_key
|
||||
state = states.setdefault(step.step_key, { 'runs' : 0 })
|
||||
state['runs'] += 1
|
||||
state['status'] = step.status
|
||||
state['url'] = ('/%s/%d/' % (WORKLOAD_PATHS.get(step.kind, 'test'), step.test_id)) if step.test_id else None
|
||||
|
||||
if step.parent_id in keys:
|
||||
hops.append((keys[step.parent_id], step.step_key, step.via))
|
||||
|
||||
rows.append({
|
||||
'step' : step, 'name' : _step_name(graph, step.step_key), 'state' : _status(step.status),
|
||||
'url' : state['url'],
|
||||
'after' : ('After %s %s' % (_step_name(graph, keys[step.parent_id]), step.via)) if step.parent_id in keys else 'First step',
|
||||
'waiting' : step.status == 'RUNNING' and approved.get(step.test_id) is False,
|
||||
})
|
||||
|
||||
taken = graphs.followed_edges(graph, hops)
|
||||
|
||||
data = {
|
||||
'run' : run,
|
||||
'pipeline' : run.pipeline,
|
||||
'state' : _status(run.status),
|
||||
'can_manage' : can_manage(profile, run.pipeline),
|
||||
'svg' : drawing.render_svg(graph, states=states, taken=taken),
|
||||
'rows' : rows,
|
||||
'signature' : '%s:%s' % (run.status, ','.join('%d=%s' % (s.id, s.status) for s in steps)),
|
||||
'live' : run.status == 'RUNNING',
|
||||
}
|
||||
|
||||
return OpenBench.views.render(request, 'pipeline_run.html', data)
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# ACTIONS #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
def _managed(request, id, action):
|
||||
|
||||
""" ( pipeline, None ) when this person may change it, ( None, response ) when not """
|
||||
|
||||
profile = viewer(request)
|
||||
if profile is None:
|
||||
return None, _turn_away(request, profile)
|
||||
|
||||
found = Pipeline.objects.filter(id=id, deleted=False).first()
|
||||
if found is None:
|
||||
return None, _missing(request)
|
||||
|
||||
if not can_manage(profile, found):
|
||||
return None, _turn_away(request, profile, id, action)
|
||||
|
||||
return (found, profile), None
|
||||
|
||||
@require_POST
|
||||
def pipeline_start(request, id):
|
||||
|
||||
managed, refusal = _managed(request, id, 'start')
|
||||
if refusal: return refusal
|
||||
found, profile = managed
|
||||
|
||||
# One at a time, so that a double click can not start every test twice
|
||||
running = PipelineRun.objects.filter(pipeline=found, status='RUNNING').first()
|
||||
if running:
|
||||
return OpenBench.views.redirect(request, '/pipelines/run/%d/' % (running.id),
|
||||
error='This pipeline is already running. Cancel that run if you want to start over')
|
||||
|
||||
run, issues = OpenBench.pipelines.start_pipeline(found, starter=profile.user.username)
|
||||
|
||||
if run is None:
|
||||
problems = '\n'.join(i['message'] for i in issues if i['level'] == 'error')
|
||||
return OpenBench.views.redirect(request, '/pipelines/%d/' % (found.id), error='Could not start the pipeline:\n' + problems)
|
||||
|
||||
first = StepRun.objects.filter(run=run).order_by('id').first()
|
||||
if run.status == 'ERROR' and first:
|
||||
return OpenBench.views.redirect(request, '/pipelines/run/%d/' % (run.id), error='The first test could not be created:\n' + first.message)
|
||||
|
||||
return OpenBench.views.redirect(request, '/pipelines/run/%d/' % (run.id), status='Run started')
|
||||
|
||||
@require_POST
|
||||
def pipeline_toggle(request, id):
|
||||
|
||||
managed, refusal = _managed(request, id, 'toggle')
|
||||
if refusal: return refusal
|
||||
found, profile = managed
|
||||
|
||||
found.enabled = not found.enabled
|
||||
found.save()
|
||||
|
||||
_audit(profile.user.username, 'PIPELINE #%d %s' % (found.id, 'RESUMED' if found.enabled else 'PAUSED'))
|
||||
return OpenBench.views.redirect(request, '/pipelines/%d/' % (found.id), status='Pipeline resumed' if found.enabled else 'Pipeline paused')
|
||||
|
||||
@require_POST
|
||||
def pipeline_delete(request, id):
|
||||
|
||||
managed, refusal = _managed(request, id, 'delete')
|
||||
if refusal: return refusal
|
||||
found, profile = managed
|
||||
|
||||
found.deleted = True
|
||||
found.save()
|
||||
|
||||
for run in PipelineRun.objects.filter(pipeline=found, status='RUNNING'):
|
||||
OpenBench.pipelines.cancel_run(run.id, profile.user.username)
|
||||
|
||||
_audit(profile.user.username, 'PIPELINE #%d DELETED' % (found.id))
|
||||
return OpenBench.views.redirect(request, '/pipelines/', status='Pipeline deleted')
|
||||
|
||||
@require_POST
|
||||
def pipeline_run_cancel(request, run_id):
|
||||
|
||||
profile = viewer(request)
|
||||
if profile is None:
|
||||
return _turn_away(request, profile)
|
||||
|
||||
run = PipelineRun.objects.select_related('pipeline').filter(id=run_id).first()
|
||||
if run is None:
|
||||
return _missing(request)
|
||||
|
||||
if not can_manage(profile, run.pipeline):
|
||||
return _turn_away(request, profile, run.pipeline_id, 'cancel')
|
||||
|
||||
if not OpenBench.pipelines.cancel_run(run.id, profile.user.username):
|
||||
return OpenBench.views.redirect(request, '/pipelines/run/%d/' % (run.id), error='This run is already over')
|
||||
|
||||
return OpenBench.views.redirect(request, '/pipelines/run/%d/' % (run.id), status='Run cancelled')
|
||||
@@ -0,0 +1,88 @@
|
||||
/* ==========================================================================
|
||||
OpenBench - Pipeline run page
|
||||
|
||||
Keeps a run up to date while it is going. The server draws the page, so this
|
||||
only asks for the page again, and swaps in the part that changed. It stops
|
||||
once the run is over, and does nothing while the tab is hidden.
|
||||
========================================================================== */
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var live = document.getElementById('pl-live');
|
||||
|
||||
if (!live || live.dataset.running !== 'true')
|
||||
return;
|
||||
|
||||
var STAMP = {
|
||||
year : 'numeric', month : '2-digit', day : '2-digit',
|
||||
hour : '2-digit', minute : '2-digit', second : '2-digit', hour12 : false,
|
||||
};
|
||||
|
||||
var timer = null;
|
||||
var busy = false;
|
||||
|
||||
// Same formatting that the base template applies when the page loads
|
||||
function stamp(root) {
|
||||
|
||||
var nodes = root.getElementsByClassName('timestamp');
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var seconds = Number(nodes[i].textContent);
|
||||
|
||||
if (isFinite(seconds) && seconds > 0)
|
||||
nodes[i].textContent = new Date(1000 * seconds).toLocaleString(undefined, STAMP);
|
||||
}
|
||||
}
|
||||
|
||||
function stop() {
|
||||
clearInterval(timer);
|
||||
document.removeEventListener('visibilitychange', onVisible);
|
||||
}
|
||||
|
||||
function onVisible() {
|
||||
if (!document.hidden)
|
||||
refresh();
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
|
||||
if (busy || document.hidden)
|
||||
return;
|
||||
|
||||
busy = true;
|
||||
|
||||
fetch(window.location.href, { credentials : 'same-origin', headers : { 'Accept' : 'text/html' } })
|
||||
|
||||
.then(function (response) {
|
||||
if (!response.ok) throw new Error('HTTP ' + response.status);
|
||||
return response.text();
|
||||
})
|
||||
|
||||
.then(function (html) {
|
||||
|
||||
var next = new DOMParser().parseFromString(html, 'text/html').getElementById('pl-live');
|
||||
|
||||
if (!next)
|
||||
return; // Logged out, or the page is gone. Leave what is shown alone
|
||||
|
||||
if (next.dataset.signature !== live.dataset.signature) {
|
||||
stamp(next);
|
||||
live.replaceWith(next);
|
||||
live = next;
|
||||
}
|
||||
|
||||
if (live.dataset.running !== 'true')
|
||||
stop();
|
||||
})
|
||||
|
||||
.catch(function () { /* Try again on the next tick */ })
|
||||
|
||||
.then(function () { busy = false; });
|
||||
}
|
||||
|
||||
timer = setInterval(refresh, 5000);
|
||||
document.addEventListener('visibilitychange', onVisible);
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,141 @@
|
||||
{% extends "OpenBench/base.html" %}
|
||||
|
||||
{% block page_head %}
|
||||
<div>
|
||||
<a class="crumb" href="/pipelines/"><i class="fa-solid fa-chevron-left"></i> Pipelines</a>
|
||||
<h1 class="page-title">{{ pipeline.name }}</h1>
|
||||
<p class="page-sub">By {{ pipeline.author|capfirst }}</p>
|
||||
</div>
|
||||
|
||||
<div class="page-actions">
|
||||
|
||||
{% if not pipeline.enabled %}<span class="badge badge-warn">Paused</span>{% endif %}
|
||||
|
||||
{% if can_manage %}
|
||||
|
||||
{% if running %}
|
||||
<a class="anchorbutton btn-start" href="/pipelines/run/{{ running.id }}/">Open the running run</a>
|
||||
{% elif pipeline.enabled and usable %}
|
||||
<form method="post" action="/pipelines/{{ pipeline.id }}/start/">
|
||||
{% csrf_token %}
|
||||
<button class="anchorbutton btn-blue" type="submit">Start run</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<button class="anchorbutton btn-disabled" type="button" disabled
|
||||
title="{% if usable %}Resume the pipeline to start it{% else %}Fix the pipeline settings first{% endif %}">Start run</button>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="/pipelines/{{ pipeline.id }}/toggle/">
|
||||
{% csrf_token %}
|
||||
<button class="anchorbutton btn-start" type="submit">{% if pipeline.enabled %}Pause{% else %}Resume{% endif %}</button>
|
||||
</form>
|
||||
|
||||
<form method="post" action="/pipelines/{{ pipeline.id }}/delete/"
|
||||
onsubmit="return confirm('Delete this pipeline? Runs that are going are cancelled. Tests that already started keep running.');">
|
||||
{% csrf_token %}
|
||||
<button class="anchorbutton btn-red" type="submit">Delete</button>
|
||||
</form>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if usable %}
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head"><h2 class="card-title">Flow</h2></div>
|
||||
<div class="pl-scroll">{{ svg|safe }}</div>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
|
||||
<div class="banner error-message" role="alert">
|
||||
<i class="fa-solid fa-circle-exclamation banner-icon"></i>
|
||||
<pre>This pipeline cannot run because its settings are damaged. An administrator can fix them on the admin site.</pre>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if issues %}
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h2 class="card-title">Checks</h2>
|
||||
<span class="count">{{ issues|length }}</span>
|
||||
</div>
|
||||
<ul class="pl-checks">
|
||||
{% for issue in issues %}
|
||||
<li class="pl-check pl-check-{{ issue.level }}">
|
||||
<i class="fa-solid {% if issue.level == 'error' %}fa-circle-exclamation{% elif issue.level == 'warning' %}fa-triangle-exclamation{% else %}fa-circle-info{% endif %}"></i>
|
||||
<span>{% if issue.name %}<strong>{{ issue.name }}</strong> {% endif %}{{ issue.message }}</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if steps %}
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h2 class="card-title">Steps</h2>
|
||||
<span class="count">{{ steps|length }}</span>
|
||||
</div>
|
||||
<table class="stripes">
|
||||
<tr class="table-header">
|
||||
<th>Step</th>
|
||||
<th>Kind</th>
|
||||
<th>Runs</th>
|
||||
<th>What happens next</th>
|
||||
</tr>
|
||||
{% for step in steps %}
|
||||
<tr>
|
||||
<td class="col-test">{{ step.name }}{% if step.start %} <span class="badge badge-info">Starts here</span>{% endif %}</td>
|
||||
<td>{{ step.kind }}</td>
|
||||
<td class="col-tc">{{ step.what }} {{ step.speed }}</td>
|
||||
<td class="pl-leads">
|
||||
{% for line in step.leads %}<div>{{ line }}</div>{% empty %}<span class="muted">The pipeline ends here</span>{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h2 class="card-title">Runs</h2>
|
||||
<span class="count">{{ runs|length }}</span>
|
||||
</div>
|
||||
{% if runs %}
|
||||
<table class="hoverable">
|
||||
<tr class="table-header">
|
||||
<th>Run</th>
|
||||
<th>Started</th>
|
||||
<th>By</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
{% for run in runs %}
|
||||
<tr data-href="/pipelines/run/{{ run.id }}/">
|
||||
<td class="col-test"><a href="/pipelines/run/{{ run.id }}/">Run {{ run.id }}</a></td>
|
||||
<td class="col-date"><span class="timestamp">{{ run.started|date:"U" }}</span></td>
|
||||
<td>{{ run.starter|capfirst }}</td>
|
||||
<td><span class="badge {{ run.state.badge }}">{{ run.state.label }}</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<i class="fa-solid fa-flag-checkered"></i>
|
||||
<p>This pipeline has not run yet.</p>
|
||||
{% if can_manage and pipeline.enabled and usable %}<p class="muted-small">Use Start run to begin with the first step.</p>{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,86 @@
|
||||
{% extends "OpenBench/base.html" %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{% static 'pipeline.js' %}?{{ static_version }}" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_head %}
|
||||
<div>
|
||||
<a class="crumb" href="/pipelines/{{ pipeline.id }}/"><i class="fa-solid fa-chevron-left"></i> {{ pipeline.name }}</a>
|
||||
<h1 class="page-title">Run {{ run.id }}</h1>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="pl-live" data-signature="{{ signature }}" data-running="{{ live|yesno:'true,false' }}">
|
||||
|
||||
<div class="pl-toolbar">
|
||||
|
||||
<span class="badge {{ state.badge }}">{{ state.label }}</span>
|
||||
|
||||
{% if can_manage and live %}
|
||||
<form method="post" action="/pipelines/run/{{ run.id }}/cancel/"
|
||||
onsubmit="return confirm('Cancel this run? Nothing more will start. Tests that already started keep running.');">
|
||||
{% csrf_token %}
|
||||
<button class="anchorbutton btn-red" type="submit">Cancel run</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
<dl class="ev-meta">
|
||||
<div><dt>Started</dt><dd><span class="timestamp">{{ run.started|date:"U" }}</span></dd></div>
|
||||
<div><dt>Started by</dt><dd>{{ run.starter|capfirst }}</dd></div>
|
||||
<div><dt>Tests created</dt><dd>{{ rows|length }}</dd></div>
|
||||
<div><dt>Pipeline</dt><dd><a href="/pipelines/{{ pipeline.id }}/">{{ pipeline.name }}</a></dd></div>
|
||||
</dl>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head"><h2 class="card-title">Path taken</h2></div>
|
||||
<div class="pl-scroll">{{ svg|safe }}</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-head">
|
||||
<h2 class="card-title">Tests</h2>
|
||||
<span class="count">{{ rows|length }}</span>
|
||||
</div>
|
||||
<table class="stripes">
|
||||
<tr class="table-header">
|
||||
<th>Step</th>
|
||||
<th>How it started</th>
|
||||
<th>Status</th>
|
||||
<th>Test</th>
|
||||
</tr>
|
||||
{% for row in rows %}
|
||||
<tr>
|
||||
<td class="col-test">{{ row.name }}</td>
|
||||
<td>{{ row.after }}</td>
|
||||
<td>
|
||||
<span class="badge {{ row.state.badge }}">{{ row.state.label }}</span>
|
||||
{% if row.waiting %}<div class="muted-small">Waiting for an approver to approve the test</div>{% endif %}
|
||||
{% if row.step.message %}<div class="muted-small pl-message">{{ row.step.message }}</div>{% endif %}
|
||||
</td>
|
||||
<td>{% if row.url %}<a href="{{ row.url }}">Test {{ row.step.test_id }}</a>{% else %}<span class="muted">Not created</span>{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if run.notes %}
|
||||
<div class="card">
|
||||
<div class="card-head"><h2 class="card-title">Why it went this way</h2></div>
|
||||
<ul class="pl-checks">
|
||||
{% for note in run.notes %}
|
||||
<li class="pl-check pl-check-info"><i class="fa-solid fa-circle-info"></i><span>{{ note }}</span></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,72 @@
|
||||
{% extends "OpenBench/base.html" %}
|
||||
|
||||
{% block page_head %}
|
||||
<div>
|
||||
<h1 class="page-title">Pipelines</h1>
|
||||
<p class="page-sub">Run a test, then let its result decide what runs next</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="stat-grid">
|
||||
<div class="stat-card stat-green">
|
||||
<div class="stat-icon"><i class="fa-solid fa-play"></i></div>
|
||||
<div>
|
||||
<div class="stat-value">{{ running }}</div>
|
||||
<div class="stat-label">Running now</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon"><i class="fa-solid fa-diagram-project"></i></div>
|
||||
<div>
|
||||
<div class="stat-value">{{ total }}</div>
|
||||
<div class="stat-label">Pipelines</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card stat-yellow">
|
||||
<div class="stat-icon"><i class="fa-solid fa-pause"></i></div>
|
||||
<div>
|
||||
<div class="stat-value">{{ paused }}</div>
|
||||
<div class="stat-label">Paused</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if rows %}
|
||||
|
||||
<table class="hoverable">
|
||||
|
||||
<tr class="table-header">
|
||||
<th>Pipeline</th>
|
||||
<th>Author</th>
|
||||
<th class="numeric">Steps</th>
|
||||
<th>Last run</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
|
||||
{% for row in rows %}
|
||||
<tr data-href="/pipelines/{{ row.pipeline.id }}/">
|
||||
<td class="col-test"><a href="/pipelines/{{ row.pipeline.id }}/">{{ row.pipeline.name }}</a></td>
|
||||
<td>{{ row.pipeline.author|capfirst }}</td>
|
||||
<td class="numeric">{{ row.steps }}</td>
|
||||
<td class="col-date">{% if row.run %}<span class="timestamp">{{ row.run.started|date:"U" }}</span>{% else %}None yet{% endif %}</td>
|
||||
<td><span class="badge {{ row.state.badge }}">{{ row.state.label }}</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
|
||||
{% else %}
|
||||
|
||||
<div class="card">
|
||||
<div class="empty-state">
|
||||
<i class="fa-solid fa-diagram-project"></i>
|
||||
<p>No pipelines yet.</p>
|
||||
<p class="muted-small">A pipeline starts a test and picks the next one from the result. An administrator adds them on the admin site for now.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Pipeline UI (phase 2) Plan
|
||||
|
||||
**Goal:** Let people see their pipelines and watch a run unfold, and start, pause and cancel them from the website.
|
||||
|
||||
**Approach:** One pure module lays out the graph and draws it as SVG, so it can be unit tested without Django. Thin views and templates sit on top of it. The page follows the existing RektBench theme (tokens in `style.css`), and the flow graph is the one element that gets real design attention: the path a run actually took is drawn bold, everything else stays quiet.
|
||||
|
||||
**Stack:** Django views and templates, inline SVG, a small fetch-and-swap script for live updates.
|
||||
|
||||
## Decisions taken from the skills
|
||||
|
||||
- Every new page and action requires a login. Closed by default.
|
||||
- One function, `can_manage(user, pipeline)`, decides who may start, pause, delete or cancel: the author, or an approver. Nothing else checks roles.
|
||||
- Mutating routes accept POST only, carry the CSRF token, take no fields from the body, and redirect only to fixed internal paths.
|
||||
- Every decision is logged as an event: who, which pipeline, allowed or denied.
|
||||
- Names of steps are user text. They are escaped when the SVG is built, and the template marks only that finished string safe.
|
||||
- The graph branches and loops, so steps are never numbered. The chip on a test page names the step and the pipeline.
|
||||
|
||||
## Tasks
|
||||
|
||||
1. **Layout and SVG (pure).** `OpenBench/pipeline_layout.py`, tests in `UnitTests/test_pipeline_layout.py`. Check: unit tests pass, including layering, loops, orphans and HTML escaping.
|
||||
2. **Cancel a run.** `cancel_run()` in `pipelines.py`, plus keeping a cancelled run cancelled when late workloads finish. Check: new Django tests fail before, pass after.
|
||||
3. **Views and permissions.** `OpenBench/pipeline_views.py`, URLs. Check: Django tests for the permission matrix (anonymous, stranger, author, approver, disabled profile) on every mutating route, and that GET never mutates.
|
||||
4. **Templates, CSS, live script, navigation.** Check: pages render in the test client, the live script is served, the full suite is green.
|
||||
5. **Chip on the test page.** Check: shown for a pipeline step, absent otherwise, absent when logged out.
|
||||
|
||||
Checkpoint after task 3: permissions are the part most worth a human look.
|
||||
Reference in new issue
Block a user