Skip to content

Commit

Permalink
shut down server checks if not on conversion page
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Dec 20, 2023
1 parent 5b314a1 commit 82eb0da
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/state/trajectory/logics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { setStatus, setIsPlaying, setError } from "../viewer/actions";
import { ReduxLogicDeps } from "../types";
import { batchActions } from "../util";

import { getSimulariumFile } from "./selectors";
import { getConversionStatus, getSimulariumFile } from "./selectors";
import {
changeToLocalSimulariumFile,
receiveTrajectory,
Expand All @@ -56,6 +56,7 @@ import {
SET_CONVERSION_TEMPLATE,
CONVERSION_NO_SERVER,
CONVERSION_SERVER_LIVE,
CONVERSION_INACTIVE,
} from "./constants";
import { ReceiveAction, LocalSimFile, HealthCheckTimeout } from "./types";
import { initialState } from "./reducer";
Expand Down Expand Up @@ -397,33 +398,41 @@ const initializeFileConversionLogic = createLogic({

controller.checkServerHealth(() => {
// callback/handler for viewer function
healthCheckSuccessful = true;
clearTimeout(healthCheckTimeouts[requestId]);
dispatch(
setConversionStatus({
status: CONVERSION_SERVER_LIVE,
})
);
done();
// only handle if we're still on the conversion page
if (getConversionStatus(getState()) !== CONVERSION_INACTIVE) {
healthCheckSuccessful = true;
clearTimeout(healthCheckTimeouts[requestId]);
dispatch(
setConversionStatus({
status: CONVERSION_SERVER_LIVE,
})
);
done();
}
}, netConnectionConfig);

// timeouts that, if they resolve, send new checks until the max # of attempts is reached
const timeoutId = setTimeout(() => {
if (!healthCheckSuccessful) {
// in case another check just resolved
clearTimeout(healthCheckTimeouts[requestId]);
if (attempts < MAX_ATTEMPTS) {
// retry the health check with incremented count
attempts++;
performHealthCheck(attempts);
} else {
// if we've done the max # of attempts, set conversionStatus
dispatch(
setConversionStatus({
status: CONVERSION_NO_SERVER,
})
);
done();
// stop process if user has navigated away from conversion page
if (
getConversionStatus(getState()) !== CONVERSION_INACTIVE
) {
if (attempts < MAX_ATTEMPTS) {
// retry the health check with incremented count
attempts++;
performHealthCheck(attempts);
} else {
// if we've done the max # of attempts, set conversionStatus
dispatch(
setConversionStatus({
status: CONVERSION_NO_SERVER,
})
);
done();
}
}
}
}, 3000);
Expand Down

0 comments on commit 82eb0da

Please sign in to comment.