Skip to content

Commit d707200

Browse files
committed
poll slower for failed instances
1 parent fad694b commit d707200

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

app/pages/project/instances/instance/InstancePage.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
112119
function 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

Comments
 (0)