Skip to content

Commit 135eb45

Browse files
committed
poll system update status
1 parent f9854c6 commit 135eb45

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

app/pages/system/UpdatePage.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Copyright Oxide Computer Company
77
*/
88

9+
import { differenceInMinutes } from 'date-fns'
910
import { useMemo } from 'react'
1011
import * as R from 'remeda'
1112

@@ -46,7 +47,29 @@ import { percentage, round } from '~/util/math'
4647

4748
export const handle = makeCrumb('System Update')
4849

49-
const statusQuery = apiq('systemUpdateStatus', {})
50+
const SEC = 1000 // ms, obviously
51+
const POLL_FAST = 20 * SEC
52+
const POLL_SLOW = 120 * SEC
53+
54+
const statusQuery = apiq(
55+
'systemUpdateStatus',
56+
{},
57+
{
58+
refetchInterval({ state: { data: status } }) {
59+
if (!status) return false // should be impossible due to prefetch
60+
61+
const now = new Date()
62+
const minSinceTargetSet = status.targetRelease
63+
? differenceInMinutes(now, status.targetRelease.timeRequested)
64+
: null
65+
const minSinceLastStepPlanned = differenceInMinutes(now, status.timeLastStepPlanned)
66+
return minSinceLastStepPlanned < 30 ||
67+
(minSinceTargetSet !== null && minSinceTargetSet < 30)
68+
? POLL_FAST
69+
: POLL_SLOW
70+
},
71+
}
72+
)
5073
const reposQuery = apiq('systemUpdateRepositoryList', { query: { limit: ALL_ISH } })
5174

5275
const refreshData = () =>

0 commit comments

Comments
 (0)