Skip to content

Commit de0d12f

Browse files
committed
Using split events
1 parent 54e1480 commit de0d12f

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

src/Pulse.Host/app/js/controllers.js

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,59 @@
33
/* Controllers */
44

55
angular.module('sc.controllers', [])
6-
.controller('heartbeatsStats', ['$scope', 'streamService', 'serviceControlService', function ($scope, streamService, serviceControlService) {
6+
.controller('heartbeatsStats', ['$scope', 'streamService', 'serviceControlService', function($scope, streamService, serviceControlService) {
77

8-
$scope.model = {active_endpoints: '?', number_of_failing_endpoints: '?'};
9-
10-
serviceControlService.getHeartbeatStats().then(function (stat) {
8+
$scope.model = { active_endpoints: 0, failing_endpoints: 0 };
9+
10+
serviceControlService.getHeartbeatStats().then(function(stat) {
1111
$scope.model.active_endpoints = stat.active_endpoints;
12-
$scope.model.number_of_failing_endpoints = stat.number_of_failing_endpoints;
12+
$scope.model.failing_endpoints = stat.failing_endpoints;
13+
});
14+
15+
streamService.subscribe($scope, 'HeartbeatGracePeriodElapsed', function(_) {
16+
$scope.model.failing_endpoints++;
17+
;
1318
});
1419

15-
streamService.subscribe($scope, 'HeartbeatSummaryChanged', function (message) {
16-
$scope.model.active_endpoints = message.active_endpoints;
17-
$scope.model.number_of_failing_endpoints = message.number_of_failing_endpoints;
20+
streamService.subscribe($scope, 'HeartbeatReceived', function(_) {
21+
$scope.model.active_endpoints++;
1822
});
23+
24+
}])
25+
.controller('heartbeats', ['$scope', 'serviceControlService', 'streamService', function($scope, serviceControlService, streamService) {
26+
27+
$scope.model = [];
1928

20-
}])
21-
.controller('heartbeats', ['$scope', 'serviceControlService', 'streamService', function ($scope, serviceControlService, streamService) {
29+
serviceControlService.getHeartbeatsList().then(function(heartbeats) {
30+
$scope.model = heartbeats;
31+
});
32+
33+
streamService.subscribe($scope, 'HeartbeatGracePeriodElapsed', function (message) {
34+
processMessage(message, false);
35+
});
36+
37+
streamService.subscribe($scope, 'HeartbeatReceived', function(message) {
38+
processMessage(message, true);
39+
});
2240

23-
$scope.model = [];
41+
function processMessage(message, active) {
42+
var idx = findHeartbeat(message.endpoint, message.machine);
2443

25-
function refresh() {
26-
serviceControlService.getHeartbeatsList().then(function(heartbeats) {
27-
$scope.model = heartbeats;
28-
});
29-
}
44+
if (idx == -1) {
45+
$scope.model.push(angular.extend({ active: active }, message));
46+
} else {
47+
$scope.model[idx].active = active;
48+
$scope.model[idx].last_sent_at = message.last_sent_at;
49+
}
50+
}
3051

31-
refresh();
52+
function findHeartbeat(endpoint, machine) {
53+
for (var i = 0; i < $scope.model.length; i++) {
54+
if ($scope.model[i].endpoint === endpoint && $scope.model[i].machine === machine) {
55+
return i;
56+
}
57+
}
3258

33-
streamService.subscribe($scope, 'HeartbeatSummaryChanged', function (_) {
34-
refresh();
35-
});
36-
}]);
59+
return -1;
60+
};
61+
}]);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<h2>Heartbeats List</h2>
22
<div class="row" ng-controller="heartbeats">
33
<div class="col-6 col-sm-6 col-lg-4" ng-repeat="heartbeat in model">
4-
<div style="margin: 5px;" ng-class="{'alert-success': heartbeat.failing == false, 'alert-danger': heartbeat.failing == true}">
5-
<h2>{{heartbeat.endpoint}}</h2>
6-
<p>Last Updated: <span moment="{{heartbeat.last_heartbeat_sent_at}}"></span></p>
4+
<div style="margin: 5px;" ng-class="{'alert-success': heartbeat.active, 'alert-danger': heartbeat.active == false}">
5+
<h4>{{heartbeat.endpoint}}@{{heartbeat.machine}}</h4>
6+
<p>Last Updated: <span moment="{{heartbeat.last_sent_at}}"></span></p>
77
</div>
88
</div>
99
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h2>Heartbeats indicators</h2>
22
<div class="well" ng-controller="heartbeatsStats" >
33
<a href="#/heartbeats" class="btn btn-success btn-lg">{{model.active_endpoints}} active endpoints</a>
4-
<a href="#/heartbeats" class="btn btn-danger btn-lg">{{model.number_of_failing_endpoints}} failing endpoints</a>
4+
<a href="#/heartbeats" class="btn btn-danger btn-lg">{{model.failing_endpoints}} failing endpoints</a>
55
</div>

0 commit comments

Comments
 (0)