Skip to content

Commit

Permalink
fixed bug in main container set interval
Browse files Browse the repository at this point in the history
  • Loading branch information
clarakm committed May 1, 2020
1 parent b979c4c commit 417ce71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
41 changes: 25 additions & 16 deletions client/containers/Main_Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Cluster_Container from './Cluster_Container.jsx';

const Main_Container = (props) => {
const { path } = props;
let awsApi;
// let awsApi;
// if (props.history.location.state) {
// awsApi = props.history.location.state.data;
// console.log('awsAPI', awsApi);
Expand Down Expand Up @@ -97,12 +97,13 @@ const Main_Container = (props) => {
let podRes;
let podUsageRes;

if (awsApi) {
serviceRes = awsApi.services;
nodeRes = awsApi.nodes;
podRes = awsApi.pods; //data on pods
podUsageRes = awsApi.podUsage; //data on pod usage
} else {
// if (awsApi) {
// serviceRes = awsApi.services;
// nodeRes = awsApi.nodes;
// podRes = awsApi.pods; //data on pods
// podUsageRes = awsApi.podUsage; //data on pod usage
// } else {
try {
const serviceReq = axios.get('/api/services');
const nodeReq = axios.get('/api/nodes');
const podReq = axios.get('/api/pods');
Expand All @@ -114,16 +115,23 @@ const Main_Container = (props) => {
nodeRes = res[1].data;
podRes = res[2].data.pod; //data on pods
podUsageRes = res[2].data.usage; //data on pod usage
}
// }
service = [];
node = [];
pod = [];
podUsage = [];

setService(service.push(...serviceRes));
setNode(node.push(...nodeRes));
setPod(pod.push(...podRes));
setPodUsage(podUsage.push(...podUsageRes));
setService(service.push(...serviceRes));
setNode(node.push(...nodeRes));
setPod(pod.push(...podRes));
setPodUsage(podUsage.push(...podUsageRes));

setData(getServices()); //set data
//data has been fetched and Loader component will through new animation
setdoneFetching(true);
setData(getServices()); //set data
//data has been fetched and Loader component will through new animation
setdoneFetching(true);
} catch (err) {
console.log('error', err);
}
};
// fetching data call for initial load and every 3 seconds
(function fetchOnLoad() {
Expand All @@ -136,8 +144,9 @@ const Main_Container = (props) => {
setInt = setInterval(() => {
console.log('setInterval called');
fetchInfo();
}, 3000);
}, 1000);
})();

//clear settimeout when component is removed from dom
return () => clearInterval(setInt);
}, [data, path]);
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/AlertsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AlertsController.getAlerts = (req, res, next) => {
if (alerts.rows[0]) {
console.log('alerts exist');
const data = alerts.rows;
console.log('data', data);
// console.log('data', data);
const alertArray = [];
for (let i = 0; i < data.length; i++) {
let obj = {
Expand All @@ -30,7 +30,7 @@ AlertsController.getAlerts = (req, res, next) => {
}

res.locals.alerts = alertArray;
console.log('locals', res.locals.alerts);
// console.log('locals', res.locals.alerts);
return next();
} else {
console.log('no alerts');
Expand Down

0 comments on commit 417ce71

Please sign in to comment.