| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 ///<reference path="../logdog-stream/logdog.ts" /> | 7 ///<reference path="../logdog-stream/logdog.ts" /> |
| 8 ///<reference path="../luci-operation/operation.ts" /> | 8 ///<reference path="../luci-operation/operation.ts" /> |
| 9 ///<reference path="../luci-sleep-promise/promise.ts" /> | 9 ///<reference path="../luci-sleep-promise/promise.ts" /> |
| 10 ///<reference path="../rpc/client.ts" /> | 10 ///<reference path="../rpc/client.ts" /> |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // Post-fetch cleanup. | 533 // Post-fetch cleanup. |
| 534 this.clearCurrentOperation(op); | 534 this.clearCurrentOperation(op); |
| 535 } | 535 } |
| 536 | 536 |
| 537 private async fetchLocationRound(l: Location, op: luci.Operation) { | 537 private async fetchLocationRound(l: Location, op: luci.Operation) { |
| 538 let buf = await this.provider.fetch(op, l); | 538 let buf = await this.provider.fetch(op, l); |
| 539 | 539 |
| 540 // Clear our fetching status. | 540 // Clear our fetching status. |
| 541 this.rendering = true; | 541 this.rendering = true; |
| 542 this.loadingState = LoadingState.RENDERING; | 542 this.loadingState = LoadingState.RENDERING; |
| 543 let hasLogs = !!(buf && buf.peek()); | 543 let hasLogs = !!(buf.peek()); |
| 544 | 544 |
| 545 // Resolve any previous rendering Promise that we have. This | 545 // Resolve any previous rendering Promise that we have. This |
| 546 // makes sure our rendering and fetching don't get more than | 546 // makes sure our rendering and fetching don't get more than |
| 547 // one round out of sync. | 547 // one round out of sync. |
| 548 if (this.renderPromise) { | 548 if (this.renderPromise) { |
| 549 await this.renderPromise; | 549 await this.renderPromise; |
| 550 } | 550 } |
| 551 | 551 |
| 552 // Clear our loading state (updates controls automatically). | 552 // Clear our loading state (updates controls automatically). |
| 553 this.loadingState = LoadingState.RENDERING; | 553 this.loadingState = LoadingState.RENDERING; |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 } | 952 } |
| 953 return opts; | 953 return opts; |
| 954 } | 954 } |
| 955 | 955 |
| 956 private async getHead(op: luci.Operation) { | 956 private async getHead(op: luci.Operation) { |
| 957 this.updateIndexes(); | 957 this.updateIndexes(); |
| 958 | 958 |
| 959 if (this.finished) { | 959 if (this.finished) { |
| 960 // Our HEAD region has met/surpassed our TAIL region, so there are no | 960 // Our HEAD region has met/surpassed our TAIL region, so there are no |
| 961 // HEAD logs to return. Only bottom. | 961 // HEAD logs to return. Only bottom. |
| 962 return null; | 962 return []; |
| 963 } | 963 } |
| 964 | 964 |
| 965 // If we have a tail pointer, only fetch HEAD up to that point. | 965 // If we have a tail pointer, only fetch HEAD up to that point. |
| 966 let opts = this.nextFetcherOptions(); | 966 let opts = this.nextFetcherOptions(); |
| 967 if (this.firstTailIndex >= 0) { | 967 if (this.firstTailIndex >= 0) { |
| 968 opts.logCount = (this.firstTailIndex - this.nextHeadIndex); | 968 opts.logCount = (this.firstTailIndex - this.nextHeadIndex); |
| 969 } | 969 } |
| 970 | 970 |
| 971 let f = | 971 let f = |
| 972 this.setActiveFetch(this.fetcher.get(op, this.nextHeadIndex, opts)); | 972 this.setActiveFetch(this.fetcher.get(op, this.nextHeadIndex, opts)); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 // length of our active array. | 1215 // length of our active array. |
| 1216 this.active = this.active.filter((entry) => { | 1216 this.active = this.active.filter((entry) => { |
| 1217 return ( | 1217 return ( |
| 1218 (!entry.buffer) || entry.buffer.peek() || | 1218 (!entry.buffer) || entry.buffer.peek() || |
| 1219 (!entry.ls.fetchedEndOfStream())); | 1219 (!entry.ls.fetchedEndOfStream())); |
| 1220 }); | 1220 }); |
| 1221 | 1221 |
| 1222 if (!this.active.length) { | 1222 if (!this.active.length) { |
| 1223 // No active streams, so we're finished. Permanently set our promise to | 1223 // No active streams, so we're finished. Permanently set our promise to |
| 1224 // the finished state. | 1224 // the finished state. |
| 1225 return; | 1225 return new BufferedLogs(null); |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 let buffers: BufferedLogs[]; | 1228 let buffers: BufferedLogs[]; |
| 1229 this.currentNextPromise = this.ensureActiveBuffers(op); | 1229 this.currentNextPromise = this.ensureActiveBuffers(op); |
| 1230 try { | 1230 try { |
| 1231 buffers = await this.currentNextPromise; | 1231 buffers = await this.currentNextPromise; |
| 1232 } finally { | 1232 } finally { |
| 1233 this.currentNextPromise = null; | 1233 this.currentNextPromise = null; |
| 1234 } | 1234 } |
| 1235 return this._aggregateBuffers(buffers); | 1235 return this._aggregateBuffers(buffers); |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 private async ensureActiveBuffers(op: luci.Operation): | 1238 private async ensureActiveBuffers(op: luci.Operation) { |
| 1239 Promise<BufferedLogs[]|null> { | |
| 1240 // Fill all buffers for all active streams. This may result in an RPC to | 1239 // Fill all buffers for all active streams. This may result in an RPC to |
| 1241 // load new buffer content for streams whose buffers are empty. | 1240 // load new buffer content for streams whose buffers are empty. |
| 1242 await Promise.all(this.active.map((entry) => entry.ensure(op))); | 1241 await Promise.all(this.active.map((entry) => entry.ensure(op))); |
| 1243 | 1242 |
| 1244 // Examine the error status of each stream. | 1243 // Examine the error status of each stream. |
| 1245 // | 1244 // |
| 1246 // The error is interesting, since we must present a common error view to | 1245 // The error is interesting, since we must present a common error view to |
| 1247 // our caller. If all returned errors are "NOT_AUTHENTICATED", we will | 1246 // our caller. If all returned errors are "NOT_AUTHENTICATED", we will |
| 1248 // return a NOT_AUTHENTICATED. Otherwise, we will return a generic | 1247 // return a NOT_AUTHENTICATED. Otherwise, we will return a generic |
| 1249 // "streams failed" error. | 1248 // "streams failed" error. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 | 1444 |
| 1446 // Get the next log and increment our index. | 1445 // Get the next log and increment our index. |
| 1447 let log = this.logs[this.index++]; | 1446 let log = this.logs[this.index++]; |
| 1448 if (this.index >= this.logs.length) { | 1447 if (this.index >= this.logs.length) { |
| 1449 this.logs = null; | 1448 this.logs = null; |
| 1450 } | 1449 } |
| 1451 return log; | 1450 return log; |
| 1452 } | 1451 } |
| 1453 } | 1452 } |
| 1454 } | 1453 } |
| OLD | NEW |