@@ -57,14 +57,16 @@ export default class Live {
57
57
/** Model of the lines of output */
58
58
private readonly events = new Heap < Event > ( ( a , b ) => {
59
59
if ( a . line === b . line ) {
60
- return a . timestamp - b . timestamp
60
+ // later timestamps get higher priority
61
+ return b . timestamp - a . timestamp
61
62
}
62
63
63
64
const stateDiff = a . stateRank - b . stateRank
64
65
if ( stateDiff !== 0 ) {
65
66
return stateDiff
66
67
} else {
67
- return a . timestamp - b . timestamp
68
+ // later timestamps get higher priority
69
+ return b . timestamp - a . timestamp
68
70
}
69
71
} )
70
72
@@ -83,6 +85,7 @@ export default class Live {
83
85
if ( tail . kind === "logs" ) {
84
86
// handle a log line
85
87
this . pushLineAndPublish ( stripColors ( data ) , cb )
88
+ return
86
89
}
87
90
88
91
// otherwise, treat it as an event
@@ -129,11 +132,7 @@ export default class Live {
129
132
return
130
133
}
131
134
132
- // inform the UI that we have updates
133
- cb ( {
134
- events : this . pushEvent ( data , metric , timestamp ) ,
135
- workers : Object . values ( this . workers ) ,
136
- } )
135
+ this . pushEvent ( data , metric , timestamp )
137
136
}
138
137
139
138
if ( name === "*" ) {
@@ -143,6 +142,12 @@ export default class Live {
143
142
// this event affects a specific worker
144
143
update ( name )
145
144
}
145
+
146
+ // inform the UI that we have updates
147
+ cb ( {
148
+ events : this . importantEvents ( ) ,
149
+ workers : Object . values ( this . workers ) ,
150
+ } )
146
151
}
147
152
}
148
153
} )
@@ -153,10 +158,14 @@ export default class Live {
153
158
154
159
/** @return the most important events, to be shown in the UI */
155
160
private importantEvents ( ) {
156
- return this . events
157
- . toArray ( )
158
- . slice ( 0 , this . opts . events || 8 )
159
- . sort ( ( a , b ) => a . timestamp - b . timestamp )
161
+ if ( this . opts . events === 0 ) {
162
+ return [ ]
163
+ } else {
164
+ return this . events
165
+ . toArray ( )
166
+ . slice ( 0 , this . opts . events || 8 ) // 8 highest priority
167
+ . sort ( ( a , b ) => a . timestamp - b . timestamp ) // sorted by time
168
+ }
160
169
}
161
170
162
171
/** Replace any timestamps with a placeholder, so that the UI can use a "5m ago" style */
@@ -182,6 +191,7 @@ export default class Live {
182
191
}
183
192
184
193
private readonly lookup : Record < string , Event > = { }
194
+
185
195
/** Add `line` to our heap `this.events` */
186
196
private pushEvent ( line : string , metric : WorkerState , timestamp : number ) {
187
197
const key = this . prepareLineForUI ( line )
@@ -207,11 +217,11 @@ export default class Live {
207
217
}
208
218
}
209
219
210
- if ( this . opts . events === 0 ) {
220
+ /* if (this.opts.events === 0) {
211
221
return []
212
222
} else {
213
223
return this.importantEvents()
214
- }
224
+ } */
215
225
}
216
226
217
227
/** This helps us parse out a [W5] style prefix for loglines, so we can intuit the worker id of the log line */
0 commit comments