Skip to content

Commit 358dcd6

Browse files
committed
fix(relay): satisfy eslint no-use-before-define in deploy poll loop
1 parent 9ce2ddf commit 358dcd6

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

src/web-ui/src/features/relay-deploy/RelayDeployWizard.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,11 @@ export const RelayDeployWizard: React.FC<RelayDeployWizardProps> = ({
362362
pollFailuresRef.current = 0;
363363
pollActiveRef.current = true;
364364

365-
const scheduleNext = () => {
366-
if (!pollActiveRef.current) return;
367-
pollRef.current = setTimeout(() => {
368-
void tick();
369-
}, POLL_INTERVAL_MS);
370-
};
371-
372-
const tick = async () => {
373-
if (!pollActiveRef.current) return;
365+
const pollOnce = async (): Promise<boolean> => {
366+
if (!pollActiveRef.current) return false;
374367
try {
375368
const res = await relayDeployApi.poll(connId, task, cursorRef.current);
376-
if (!pollActiveRef.current) return;
369+
if (!pollActiveRef.current) return false;
377370
cursorRef.current = res.cursor;
378371
pollFailuresRef.current = 0;
379372
if (res.output) {
@@ -394,25 +387,36 @@ export const RelayDeployWizard: React.FC<RelayDeployWizardProps> = ({
394387
window.setTimeout(() => setStep('register'), 800);
395388
}
396389
}
397-
return;
390+
return false;
398391
}
399392
} catch (e) {
400393
// Transient SSH blips are expected (the manager auto-reconnects);
401394
// only give up after repeated failures.
402-
if (!pollActiveRef.current) return;
395+
if (!pollActiveRef.current) return false;
403396
pollFailuresRef.current += 1;
404397
log.warn('task poll failed', e);
405398
if (pollFailuresRef.current >= MAX_POLL_FAILURES) {
406399
stopPolling();
407400
setTaskStatus('failed');
408401
setTaskLog((prev) => `${prev}\n[poll] ${errMsg(e)}`);
409-
return;
402+
return false;
410403
}
411404
}
412-
scheduleNext();
405+
return pollActiveRef.current;
413406
};
414407

415-
void tick();
408+
const scheduleNext = () => {
409+
if (!pollActiveRef.current) return;
410+
pollRef.current = setTimeout(() => {
411+
void pollOnce().then((shouldContinue) => {
412+
if (shouldContinue) scheduleNext();
413+
});
414+
}, POLL_INTERVAL_MS);
415+
};
416+
417+
void pollOnce().then((shouldContinue) => {
418+
if (shouldContinue) scheduleNext();
419+
});
416420
}, [runPreflight, stopPolling, t]);
417421

418422
const handleInstallDocker = async () => {

0 commit comments

Comments
 (0)