Skip to content

Commit

Permalink
fix(HMS-4012): increase polling and timeout intervals in wizard
Browse files Browse the repository at this point in the history
Increased:
- polling to 2s from 1s
- timeout to 15 minutes from 3s

This should give the user plenty of time to register the IPA server
without a need to click on the "Test" button.

Elapsed time logic was changed to be more accurate.

Signed-off-by: Petr Vobornik <[email protected]>
  • Loading branch information
pvoborni committed Jun 17, 2024
1 parent 7be1484 commit b3e2776
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,17 @@ interface VerifyRegistryProps {

const VerifyRegistry = (props: VerifyRegistryProps) => {
const [isPolling, setIsPolling] = useState<boolean>(true);
const [startTime, setStartTime] = useState<number>(Date.now());

const base_url = '/api/idmsvc/v1';
const resources_api = ResourcesApiFactory(undefined, base_url, undefined);
const timeout = 3 * 1000; // Seconds

/** TODO Extract this effect in a hook to simplify this code */
const second = 1000;
const checkInterval = 2 * second;
const timeout = 15 * 60 * second; // 15 minutes

useEffect(() => {
let intervalId: NodeJS.Timeout | null = null;
let elapsedTime = 0;
let newState: VerifyState = props.state;
let domain: Domain | undefined = undefined;
const stopPolling = (state: VerifyState, domain?: Domain) => {
Expand Down Expand Up @@ -205,12 +207,13 @@ const VerifyRegistry = (props: VerifyRegistryProps) => {
}
}

const elapsedTime = Date.now() - startTime;

if (newState !== undefined && newState !== props.state) {
switch (newState) {
case 'timed-out':
case 'waiting':
props.onChange(newState);
// setState(newState);
break;
default:
if (elapsedTime >= timeout) {
Expand All @@ -223,15 +226,14 @@ const VerifyRegistry = (props: VerifyRegistryProps) => {
break;
}
}
elapsedTime += 1000; // Increase elapsed time by 1 second
if (elapsedTime > timeout) {
newState = 'timed-out';
stopPolling(newState);
}
};

fetchData();
intervalId = setInterval(fetchData, 1000);
intervalId = setInterval(fetchData, checkInterval);

return () => {
if (intervalId) {
Expand All @@ -241,8 +243,8 @@ const VerifyRegistry = (props: VerifyRegistryProps) => {
}, [isPolling]);

const onRetry = () => {
setStartTime(Date.now());
props.onChange('initial');
// setState('initial');
setIsPolling(true);
};

Expand Down

0 comments on commit b3e2776

Please sign in to comment.