layerindex-web/templates/layerindex/task.html
Paul Eggleton d063aab917 Show progress when running comparison update tasks
Provide a mechanism for distro comparison update tasks to display
progress. In practice this means the update command needs to write the
progress percentage to a file and then the log view (which is polled by
the frontend) reads this file. Originally I was going to use a FIFO for
this but that turned out to be a but unreliable; I also tried to use
Celery's state mechanism to pass it back but I simply could not get it
to work. The file-based mechanism is good enough though.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
2018-09-20 16:04:49 +12:00

94 lines
2.9 KiB
HTML

{% extends "base.html" %}
{% load i18n %}
{% load extrafilters %}
{% comment %}
layerindex-web - task page
Copyright (C) 2018 Intel Corporation
Licensed under the MIT license, see COPYING.MIT for details
{% endcomment %}
<!--
{% block title_append %} - task status{% endblock %}
-->
{% block content %}
{% autoescape on %}
<p>Task status for {{ update.task_id }} started by {{ update.triggered_by }} on {{ update.started }}<span id="task_status_fragment">{% if update.finished %} (finished in {{ update.started | timesince2:update.finished }}){% endif %}</span>:</p>
<pre id="task_log" class="vertical-scroll">{{ update.log }}</pre>
{% if not update.finished %}
<div class="progress">
<div id="progressbar" class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
</div>
</div>
{% endif %}
{% if update.comparisonrecipeupdate_set.exists %}
<h3>Updated comparison recipes</h3>
<ul>
{% for recipeupdate in update.comparisonrecipeupdate_set.all %}
<li><a href="{% url 'comparison_recipe' recipeupdate.recipe.id %}">{{ recipeupdate.recipe.pn }}</a> {% if recipeupdate.meta_updated and recipeupdate.link_updated %}(meta, link){% elif recipeupdate.link_updated %}(link){% elif recipeupdate.meta_updated %}(meta){% endif %}</li>
{% endfor %}
</ul>
{% endif %}
{% endautoescape %}
{% endblock %}
{% block footer %}
{% endblock %}
{% block scripts %}
<script>
var posn = 0;
var done = '0';
var duration = ''
var scrolling = true;
function updateLog() {
$.ajax({
url: '{{ log_url }}?start=' + posn,
success: function( data, code, xhr ) {
task_log = $("#task_log")
task_log.append(data);
if(scrolling) {
task_log.animate({ scrollTop: task_log.prop('scrollHeight') }, "slow");
}
posn += data.length
done = xhr.getResponseHeader('Task-Done')
duration = xhr.getResponseHeader('Task-Duration')
progress = parseInt(xhr.getResponseHeader('Task-Progress')) || 0;
if(progress) {
$('#progressbar').css('width', progress + '%').attr('aria-valuenow', progress);
$("#progressbar").html(progress + '%')
}
}
}).always(function () {
if(done == '1') {
$("#task_status_fragment").html(" (finished in " + duration + ")")
}
else {
window.setTimeout(updateLog, 1000);
}
});
}
$("#task_log").scroll(function() {
scrolling = ($(this).scrollTop() + $(this).height() + 50 > $(this).prop('scrollHeight'))
});
$(document).ready(function() {
{% if not update.finished %}
updateLog();
{% endif %}
});
</script>
{% endblock %}