Chromium Code Reviews| 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 It contains the definition of the following Behaviors: | 6 It contains the definition of the following Behaviors: |
| 7 | 7 |
| 8 SwarmingBehaviors.CommonBehavior | 8 SwarmingBehaviors.CommonBehavior |
| 9 | 9 |
| 10 To use it, include | 10 To use it, include |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 console.log("ignoring failure because a second request happened."); | 150 console.log("ignoring failure because a second request happened."); |
| 151 this.splice(busyArr, idx, 1, {status:false}); | 151 this.splice(busyArr, idx, 1, {status:false}); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 this.splice(busyArr, idx, 1, {status:false}); | 154 this.splice(busyArr, idx, 1, {status:false}); |
| 155 return Promise.reject(reason); | 155 return Promise.reject(reason); |
| 156 }.bind(this)); | 156 }.bind(this)); |
| 157 }, | 157 }, |
| 158 | 158 |
| 159 _humanDuration: function(timeInSecs) { | 159 _humanDuration: function(timeInSecs) { |
| 160 return sk.human.strDuration(timeInSecs) || "0s"; | 160 // If the timeInSecs is 0 (e.g. duration of Terminate bot tasks), we |
| 161 // still want to display 0s. | |
| 162 if (timeInSecs === 0 || timeInSecs === "0") { | |
|
stephana
2017/05/31 15:00:42
.... timeInSecs === "0" should be omitted IMO. Str
kjlubick
2017/05/31 15:02:53
I put it in there such that 0 and "0" become "0s"
stephana
2017/05/31 17:29:19
Ack
| |
| 163 return "0s"; | |
| 164 } | |
| 165 // Otherwise, if timeInSecs is falsey (e.g. undefined), return empty | |
| 166 // string to reflect that. | |
| 167 if (!timeInSecs) { | |
| 168 return ""; | |
| 169 } | |
| 170 ptimeInSecs = parseFloat(timeInSecs); | |
| 171 // On a bad parse (shouldn't happen), show original. | |
| 172 if (!ptimeInSecs) { | |
| 173 return timeInSecs + " seconds"; | |
| 174 } | |
| 175 | |
| 176 // For times greater than a minute, make them human readable | |
| 177 // e.g. 2h 43m or 13m 42s | |
| 178 if (ptimeInSecs > 60){ | |
| 179 return sk.human.strDuration(ptimeInSecs); | |
| 180 } | |
| 181 // For times less than a minute, add 10ms resolution. | |
| 182 return ptimeInSecs.toFixed(2)+"s"; | |
| 161 }, | 183 }, |
| 162 | 184 |
| 163 _not: function(a) { | 185 _not: function(a) { |
| 164 return !a; | 186 return !a; |
| 165 }, | 187 }, |
| 166 | 188 |
| 167 _or: function() { | 189 _or: function() { |
| 168 var result = false; | 190 var result = false; |
| 169 // can't use .foreach, as arguments isn't really an Array. | 191 // can't use .foreach, as arguments isn't really an Array. |
| 170 for (var i = 0; i < arguments.length; i++) { | 192 for (var i = 0; i < arguments.length; i++) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 } | 261 } |
| 240 return this._humanDuration((second.getTime() - first.getTime())/1000); | 262 return this._humanDuration((second.getTime() - first.getTime())/1000); |
| 241 }, | 263 }, |
| 242 | 264 |
| 243 _truthy: function(a){ | 265 _truthy: function(a){ |
| 244 return !!a; | 266 return !!a; |
| 245 } | 267 } |
| 246 }; | 268 }; |
| 247 })(); | 269 })(); |
| 248 </script> | 270 </script> |
| OLD | NEW |