Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / app / assets / javascripts / work_unit_log.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 $(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(event, eventData){
6     var wasatbottom, txt;
7     if (this != event.target) {
8         // Not interested in events sent to child nodes.
9         return;
10     }
11
12     if (!('properties' in eventData)) {
13         return;
14     }
15
16     txt = '';
17     if ('text' in eventData.properties &&
18        eventData.properties.text.length > 0) {
19         txt += eventData.properties.text;
20         if (txt.slice(txt.length-1) != "\n") {
21             txt += "\n";
22         }
23     }
24     if (eventData.event_type == 'update' &&
25         eventData.object_uuid.indexOf("-dz642-") == 5 &&
26         'old_attributes' in eventData.properties &&
27         'new_attributes' in eventData.properties) {
28         // Container update
29         if (eventData.properties.old_attributes.state != eventData.properties.new_attributes.state) {
30             var stamp = eventData.event_at + " ";
31             switch(eventData.properties.new_attributes.state) {
32             case "Queued":
33                 txt += stamp + "Container "+eventData.object_uuid+" was returned to the queue\n";
34                 break;
35             case "Locked":
36                 txt += stamp + "Container "+eventData.object_uuid+" was taken from the queue by a dispatch process\n";
37                 break;
38             case "Running":
39                 txt += stamp + "Container "+eventData.object_uuid+" started\n";
40                 break;
41             case "Complete":
42                 var outcome = eventData.properties.new_attributes.exit_code === 0 ? "success" : "failure";
43                 txt += stamp + "Container "+eventData.object_uuid+" finished with exit code " +
44                     eventData.properties.new_attributes.exit_code +
45                     " ("+outcome+")\n";
46                 break;
47             case "Cancelled":
48                 txt += stamp + "Container "+eventData.object_uuid+" was cancelled\n";
49                 break;
50             default:
51                 // Unknown state -- unexpected, might as well log it.
52                 txt += stamp + "Container "+eventData.object_uuid+" changed state to " +
53                     eventData.properties.new_attributes.state + "\n";
54                 break;
55             }
56         }
57     }
58
59     if (txt == '') {
60         return;
61     }
62
63     wasatbottom = ($(this).scrollTop() + $(this).height() >= this.scrollHeight);
64     if (eventData.prepend) {
65         $(this).prepend(txt);
66     } else {
67         $(this).append(txt);
68     }
69     if (wasatbottom) {
70         this.scrollTop = this.scrollHeight;
71     }
72 });