MCPcopy Index your code
hub / github.com/coder/coder / estimateFinish

Function estimateFinish

site/src/pages/WorkspacePage/WorkspaceBuildProgress.tsx:34–62  ·  view source on GitHub ↗
(
	startedAt: Dayjs,
	p50: number,
	p95: number,
)

Source from the content-addressed store, hash-verified

32};
33
34const 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
64interface WorkspaceBuildProgressProps {
65 workspace: Workspace;

Callers 1

updateProgressFunction · 0.85

Calls 2

secondsLeftFunction · 0.85
diffMethod · 0.65

Tested by

no test coverage detected