Skip to content

Commit 5582fc8

Browse files
authored
Implement pipeline run status auto-refresh #390 (#428)
* Implement pipeline run status auto-refresh #390 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Display a "toast" notification on status refresh #390 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Move the toast code logic to a "main.js" function #390 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Fix unit test and extend the CHANGELOG #390 Signed-off-by: Thomas Druez <tdruez@nexb.com>
1 parent 81d8ac5 commit 5582fc8

File tree

14 files changed

+172
-7
lines changed

14 files changed

+172
-7
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ v31.0.0 (next)
77
- WARNING: Drop support for Python 3.6 and 3.7. Add support for Python 3.10.
88
Upgrade Django to version 4.x series.
99

10+
- Implement run status auto-refresh using the htmx JavaScript library.
11+
The statuses of queued and running pipeline are now automatically refreshed
12+
in the project list and project details views every 10 seconds.
13+
A new "toast" type of notification is displayed along the status update.
14+
https://github.com/nexB/scancode.io/issues/390
15+
1016
- Ensure the worker service waits for migrations completion before starting.
1117
To solve this issue we install the wait-for-it script available in
1218
Debian by @vishnubob and as suggested in the Docker documentation.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2+
3+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4+
5+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6+
7+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

scancodeio/static/bulma-toast-2.4.1.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
about_resource: bulma-toast-2.4.1.min.js
2+
name: bulma-toast
3+
version: 2.4.1
4+
download_url: https://github.com/rfoel/bulma-toast/releases/download/v2.4.1/bulma-toast-2.4.1.tgz
5+
description: Bulma's pure JavaScript extension to display toasts
6+
homepage_url: https://rfoel.com/bulma-toast
7+
license_expression: mit
8+
attribute: yes
9+
checksum_md5: 9636a121215045c5b602d739f5610b6f
10+
checksum_sha1: 1e0ea72a810af2cc11a5c39cf4051567f5c29434
11+
package_url: pkg:github/rfoel/bulma-toast@2.4.1?download_url=https://github.com/rfoel/bulma-toast/releases/download/v2.4.1/bulma-toast-2.4.1.tgz
12+
licenses:
13+
- key: mit
14+
name: MIT License
15+
file: mit.LICENSE

scancodeio/static/htmx-1.7.0.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
about_resource: htmx-1.7.0.tar.gz
2+
name: htmx
3+
version: 1.7.0
4+
download_url: https://github.com/bigskysoftware/htmx/archive/refs/tags/v1.7.0.tar.gz
5+
description: high power tools for html
6+
homepage_url: https://htmx.org/
7+
license_expression: bsd-simplified
8+
attribute: yes
9+
checksum_md5: 60f07b7bf13a62a16d4792489252f1dd
10+
checksum_sha1: 3712bcbc653d0f0404e94c5d74233f70b61eb45e
11+
package_url: pkg:github/bigskysoftware/htmx@1.7.0
12+
licenses:
13+
- key: bsd-simplified
14+
name: BSD-2-Clause
15+
file: bsd-simplified.LICENSE

scancodeio/static/main.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,39 @@ document.addEventListener('DOMContentLoaded', function () {
157157
}
158158

159159
});
160+
161+
// Toasts (requires bulma-toast.js)
162+
163+
function displayPipelineStatusToast(run_status, pipeline_name, project_url) {
164+
const default_options = {
165+
"position": "top-center",
166+
"dismissible": true,
167+
"closeOnClick": false,
168+
"pauseOnHover": true,
169+
"duration": 30000 // 30 secs
170+
}
171+
let custom_options;
172+
173+
if (run_status === "running") {
174+
custom_options = {
175+
"message": `Pipeline ${pipeline_name} started.`,
176+
"type": "is-info",
177+
"duration": 3000 // 3 secs
178+
}
179+
}
180+
else if (run_status === "success") {
181+
custom_options = {
182+
"message": `Pipeline ${pipeline_name} completed successfully.\n` +
183+
`<a href="${project_url}">Access or refresh the project page for results.</a>`,
184+
"type": "is-success is-inline-block",
185+
}
186+
}
187+
else {
188+
custom_options = {
189+
"message": `Pipeline ${pipeline_name} ${run_status}.`,
190+
"type": "is-danger",
191+
}
192+
}
193+
194+
bulmaToast.toast({...default_options, ...custom_options});
195+
}

scanpipe/templates/scanpipe/base.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
<script src="{% static 'main.js' %}" crossorigin="anonymous"></script>
5353
<script src="{% static 'fontawesome-5.15.1.all.min.js' %}" crossorigin="anonymous"></script>
5454
<script src="{% static 'highlight-10.6.0.min.js' %}" crossorigin="anonymous"></script>
55+
<script src="{% static 'bulma-toast-2.4.1.min.js' %}" crossorigin="anonymous" defer></script>
56+
<script src="{% static 'htmx-1.7.0.min.js' %}" crossorigin="anonymous" defer></script>
5557
{% block scripts %}{% endblock %}
5658
</body>
5759
</html>

scanpipe/templates/scanpipe/includes/run_modal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
let $modal = document.getElementById(modal_id);
88
let run_uuid = event.detail.$button.dataset.uuid;
9-
let run_detail_url = `/runs/${run_uuid}/`;
9+
let run_detail_url = `/run/${run_uuid}/`;
1010
$modal.innerHTML = "";
1111

1212
fetch(run_detail_url).then(function (response) {
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
{% if run.status == run.Status.SUCCESS %}
1+
{% if run.status == run.Status.RUNNING or run.status == run.Status.QUEUED %}
2+
<span class="tag is-info" hx-get="{% url 'run_status' run.uuid %}?current_status={{ run.status }}" hx-trigger="load delay:10s" hx-swap="outerHTML">
3+
{% if run.status == run.Status.RUNNING %}
4+
Running <i class="fas fa-spinner fa-pulse ml-1" aria-hidden="true"></i>
5+
{% elif run.status == run.Status.QUEUED %}
6+
Queued <i class="fas fa-clock ml-1"></i>
7+
{% endif %}
8+
</span>
9+
{% elif run.status == run.Status.SUCCESS %}
210
<span class="tag is-success">Success</span>
311
{% elif run.status == run.Status.FAILURE %}
412
<span class="tag is-danger">Failure</span>
5-
{% elif run.status == run.Status.RUNNING %}
6-
<span class="tag is-info">Running <i class="fas fa-spinner fa-pulse ml-1" aria-hidden="true"></i></span>
7-
{% elif run.status == run.Status.QUEUED %}
8-
<span class="tag is-info">Queued <i class="fas fa-clock ml-1"></i></span>
913
{% elif run.status == run.Status.STALE %}
1014
<span class="tag is-dark">Stale</span>
1115
{% elif run.status == run.Status.STOPPED %}
1216
<span class="tag is-danger">Stopped</span>
1317
{% else %}
1418
<span class="tag is-light">Not started</span>
19+
{% endif %}
20+
21+
{% if status_changed %}
22+
<script>
23+
displayPipelineStatusToast(
24+
run_status="{{ run.status }}",
25+
pipeline_name="{{ run.pipeline_name }}",
26+
project_url="{{ run.project.get_absolute_url }}"
27+
);
28+
</script>
1529
{% endif %}

0 commit comments

Comments
 (0)