@@ -107,8 +107,15 @@ InstancePage.loader = async ({ params }: LoaderFunctionArgs) => {
107107 return null
108108}
109109
110- const POLL_INTERVAL = 1000
110+ const sec = 1000 // ms, obviously
111+ const POLL_INTERVAL_FAST = 1 * sec
112+ const POLL_INTERVAL_SLOW = 60 * sec
111113
114+ // We're using this logic here on instance detail, but not on instance list.
115+ // Instance list will only poll for the transitioning case. We don't show
116+ // anything about cooldown on the instance list, so the only point of polling
117+ // would be to catch a restart when it happens. But with the cooldown period
118+ // being an hour, we'd be doing a _lot_ of unnecessary polling on the list page.
112119function shouldPoll ( instance : Instance ) {
113120 if ( instanceTransitioning ( instance ) ) return 'transition'
114121 if ( instanceCoolingDown ( instance ) ) return 'cooldown'
@@ -146,8 +153,14 @@ export function InstancePage() {
146153 query : { project : instanceSelector . project } ,
147154 } ,
148155 {
149- refetchInterval : ( { state : { data : instance } } ) =>
150- instance && shouldPoll ( instance ) ? POLL_INTERVAL : false ,
156+ refetchInterval : ( { state : { data : instance } } ) => {
157+ const pollReason = instance ? shouldPoll ( instance ) : null
158+ return match ( pollReason )
159+ . with ( 'transition' , ( ) => POLL_INTERVAL_FAST )
160+ . with ( 'cooldown' , ( ) => POLL_INTERVAL_SLOW )
161+ . with ( null , ( ) => false as const )
162+ . exhaustive ( )
163+ } ,
151164 }
152165 )
153166
0 commit comments