( startedAt: Dayjs, p50: number, p95: number, )
| 32 | }; |
| 33 | |
| 34 | const estimateFinish = ( |
| 35 | startedAt: Dayjs, |
| 36 | p50: number, |
| 37 | p95: number, |
| 38 | ): [number | undefined, string] => { |
| 39 | const sinceStart = dayjs().diff(startedAt); |
| 40 | const secondsLeft = (est: number) => { |
| 41 | const max = Math.max( |
| 42 | Math.ceil(dayjs.duration((1 - sinceStart / est) * est).asSeconds()), |
| 43 | 0, |
| 44 | ); |
| 45 | return Number.isNaN(max) ? 0 : max; |
| 46 | }; |
| 47 | |
| 48 | // Under-promise, over-deliver with the 95th percentile estimate. |
| 49 | const highGuess = secondsLeft(p95); |
| 50 | |
| 51 | const anyMomentNow: [number | undefined, string] = [ |
| 52 | undefined, |
| 53 | "Any moment now...", |
| 54 | ]; |
| 55 | |
| 56 | const p50percent = (sinceStart * 100) / p50; |
| 57 | if (highGuess <= 0) { |
| 58 | return anyMomentNow; |
| 59 | } |
| 60 | |
| 61 | return [p50percent, `Up to ${highGuess} seconds remaining...`]; |
| 62 | }; |
| 63 | |
| 64 | interface WorkspaceBuildProgressProps { |
| 65 | workspace: Workspace; |
no test coverage detected