Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/scorekeeper-status-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import HealthCheckBar from "./HealthCheckBar";
import { Identicon } from "@polkadot/react-identicon";
import EraStatsBar from "./EraStatsBar";
import { debounce } from "lodash";
import { REFRESH_INTERVAL } from "./Constants";

interface Job {
name: string;
Expand Down Expand Up @@ -50,7 +51,7 @@ const App = () => {
const [jobs, setJobs] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [hasError, setHasError] = useState(false);
const [refreshInterval, setRefreshInterval] = useState(500); // Default refresh interval
const [refreshInterval, setRefreshInterval] = useState(REFRESH_INTERVAL); // Default refresh interval
const [nominators, setNominators] = useState([]);

const fetchData = useCallback(async () => {
Expand All @@ -66,17 +67,17 @@ const App = () => {
})),
);
setHasError(false);
setRefreshInterval(800); // Reset to faster refresh rate on success
setRefreshInterval(5000); // Reset to faster refresh rate on success
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded value here ?

Comment says "faster", but 5000 is the same value of the REFRESH_INTERVAL constant, which seems to be used for the "Slow down" scenario...

=> maybe we need REFRESH_INTERVAL_FAST and REFRESH_INTERVAL_SLOW ?

} else {
// Handle empty response
console.log("Received empty response");
setHasError(true);
setRefreshInterval(5000); // Slow down the refresh rate
setRefreshInterval(REFRESH_INTERVAL); // Slow down the refresh rate
}
} catch (error) {
console.error("Error fetching job data:", error);
setHasError(true);
setRefreshInterval(5000); // Slow down the refresh rate on error
setRefreshInterval(REFRESH_INTERVAL); // Slow down the refresh rate on error

// Provide more specific error handling
if (error.response) {
Expand Down Expand Up @@ -122,12 +123,12 @@ const App = () => {
}, [currentEndpoint]);

useEffect(() => {
const interval = setInterval(fetchData, 500);
const interval = setInterval(fetchData, REFRESH_INTERVAL);
return () => clearInterval(interval);
}, [fetchData]);

useEffect(() => {
const interval = setInterval(fetchNominatorsData, 500);
const interval = setInterval(fetchNominatorsData, REFRESH_INTERVAL);
return () => clearInterval(interval);
}, [fetchNominatorsData]);

Expand Down
1 change: 1 addition & 0 deletions packages/scorekeeper-status-ui/src/Constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const REFRESH_INTERVAL = 5000;
3 changes: 2 additions & 1 deletion packages/scorekeeper-status-ui/src/EraStatsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FiServer,
FiUserCheck,
} from "react-icons/fi";
import { REFRESH_INTERVAL } from "./Constants";

const EraStatsBar = ({ currentEndpoint }) => {
const [eraStats, setEraStats] = useState({
Expand All @@ -29,7 +30,7 @@ const EraStatsBar = ({ currentEndpoint }) => {
}
};

const interval = setInterval(fetchEraStats, 500);
const interval = setInterval(fetchEraStats, REFRESH_INTERVAL);
return () => clearInterval(interval);
}, [currentEndpoint]);

Expand Down
5 changes: 3 additions & 2 deletions packages/scorekeeper-status-ui/src/HealthCheckBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
FiClock,
FiInfo,
FiWifi,
} from "react-icons/fi"; // Added FiClock for the uptime icon
} from "react-icons/fi";
import { REFRESH_INTERVAL } from "./Constants"; // Added FiClock for the uptime icon

const HealthCheckBar = ({ currentEndpoint }) => {
const [healthData, setHealthData] = useState({
Expand All @@ -28,7 +29,7 @@ const HealthCheckBar = ({ currentEndpoint }) => {
}
};

const interval = setInterval(fetchHealthData, 500);
const interval = setInterval(fetchHealthData, REFRESH_INTERVAL);
return () => clearInterval(interval);
}, [currentEndpoint]);

Expand Down