Mercurial > piecrust2
comparison piecrust/resources/server/piecrust-debug-info.js @ 219:d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
The server can now run an endpoint that streams pipeline status, including
errors or "fixed" statuses.
As a result, I had to investigate using event-loop based server alternatives,
before I figured out the correct flag to set in Werkzeug. Support for Gunicorn
is therefore now possible, although disabled by default. I will come in handy
though when proper support for CMS-mode is enabled.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 02 Feb 2015 08:34:44 -0800 |
parents | |
children | 9612cfc6455a |
comparison
equal
deleted
inserted
replaced
218:10f24c62b05b | 219:d7a548ebcd58 |
---|---|
1 var eventSource = new EventSource("/__piecrust_debug/pipeline_status"); | |
2 | |
3 //window.onbeforeunload = function(e) { | |
4 // console.log("Disconnecting SSE.", e); | |
5 // eventSource.close(); | |
6 //}; | |
7 | |
8 eventSource.onerror = function(e) { | |
9 console.log("Error with SSE, closing.", e); | |
10 eventSource.close(); | |
11 }; | |
12 | |
13 eventSource.addEventListener('pipeline_success', function(e) { | |
14 var placeholder = document.getElementById('piecrust-debug-info-pipeline-status'); | |
15 //if (placeholder.firstChild !== null) | |
16 placeholder.removeChild(placeholder.firstChild); | |
17 }); | |
18 | |
19 eventSource.addEventListener('pipeline_error', function(e) { | |
20 var obj = JSON.parse(e.data); | |
21 | |
22 var outer = document.createElement('div'); | |
23 outer.style = 'padding: 1em;'; | |
24 for (var i = 0; i < obj.assets.length; ++i) { | |
25 var item = obj.assets[i]; | |
26 var markup = ( | |
27 '<p>Error processing: <span style="font-family: monospace;">' + | |
28 item.path + '</span></p>\n' + | |
29 '<ul>'); | |
30 for (var j = 0; j < item.errors.length; ++j) { | |
31 markup += ( | |
32 '<li style="font-family: monospace;">' + | |
33 item.errors[j] + | |
34 '</li>\n'); | |
35 } | |
36 markup += '</ul>\n'; | |
37 var entry = document.createElement('div'); | |
38 entry.innerHTML = markup; | |
39 outer.appendChild(entry); | |
40 } | |
41 | |
42 var placeholder = document.getElementById('piecrust-debug-info-pipeline-status'); | |
43 placeholder.appendChild(outer); | |
44 }); | |
45 |