Skip to content

Commit

Permalink
added ingress_rules refresh changes (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: Tanmoy Sarkar <[email protected]>
  • Loading branch information
TMuthu and tanmoysrt authored Oct 2, 2023
1 parent ca824b7 commit 2903ef4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/pages/ingress_rules.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import {
import { SyncIcon } from "@primer/octicons-react";
import { useContext, useEffect, useState } from "react";
import ControllerContext from "../context/controller/ControllerContext";
import { formatReadableDate, showErrorToast, showSuccessToast } from "../utils";
import {
formatReadableDate,
showErrorToast,
showSuccessToast,
runTaskAtInterval,
} from "../utils";
import tag_color from "../config/tag_color";
import { AddIcon } from "@chakra-ui/icons";
import AddIngressRulesModal from "../components/addIngressRulesModal";
Expand Down Expand Up @@ -94,6 +99,8 @@ export default function IngressRulesPage() {

useEffect(() => {
fetchRules();
const intervalID = runTaskAtInterval(fetchRules, 10000);
return () => clearInterval(intervalID);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
12 changes: 8 additions & 4 deletions src/pages/redirect_rules.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import {
import { SyncIcon } from "@primer/octicons-react";
import { useContext, useEffect, useState } from "react";
import ControllerContext from "../context/controller/ControllerContext";
import { formatReadableDate, showErrorToast, showSuccessToast } from "../utils";
import {
formatReadableDate,
showErrorToast,
showSuccessToast,
runTaskAtInterval,
} from "../utils";
import tag_color from "../config/tag_color";
import { AddIcon } from "@chakra-ui/icons";
import AddRedirectRulesModal from "../components/addRedirectRulesModal";
Expand Down Expand Up @@ -77,9 +82,8 @@ export default function RedirectRulesPage() {

useEffect(() => {
fetchRules();
setInterval(() => {
fetchRules();
}, 10000);
const intervalID = runTaskAtInterval(fetchRules, 10000);
return () => clearInterval(intervalID);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
9 changes: 9 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ export function showSuccessToast(toast, message){
isClosable: true,
position: "top"
});
}

export function runTaskAtInterval(callback, interval) {
const intervalId = setInterval(() => {
callback(); // Call the provided callback function
}, interval);

// Return the interval ID in case you want to clear it later
return intervalId;
}

0 comments on commit 2903ef4

Please sign in to comment.