#503 fix(container-stats): fix container stats timer not being properly canceled. (#504)

pull/526/head
lpfeup 2017-01-21 05:04:28 +00:00 committed by Anthony Lapenna
parent 7d78871eee
commit 579241db92
1 changed files with 10 additions and 2 deletions

View File

@ -114,6 +114,12 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
});
$scope.networkLegend = $sce.trustAsHtml(networkChart.generateLegend());
function setUpdateStatsTimeout() {
if(!destroyed) {
timeout = $timeout(updateStats, 5000);
}
}
function updateStats() {
Container.stats({id: $stateParams.id}, function (d) {
var arr = Object.keys(d).map(function (key) {
@ -129,15 +135,17 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
updateCpuChart(d);
updateMemoryChart(d);
updateNetworkChart(d);
timeout = $timeout(updateStats, 5000);
setUpdateStatsTimeout();
}, function () {
Messages.error('Unable to retrieve stats', {}, 'Is this container running?');
timeout = $timeout(updateStats, 5000);
setUpdateStatsTimeout();
});
}
var destroyed = false;
var timeout;
$scope.$on('$destroy', function () {
destroyed = true;
$timeout.cancel(timeout);
});