File tree 4 files changed +17
-14
lines changed
4 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -30,23 +30,23 @@ function boot (env) {
30
30
store . ensureIndexes ( ctx . devicestatus ( ) , ctx . devicestatus . indexedFields ) ;
31
31
store . ensureIndexes ( ctx . profile ( ) , ctx . profile . indexedFields ) ;
32
32
33
- ctx . heartbeat = require ( './ticker ' ) ( env , ctx ) ;
33
+ ctx . bus = require ( './bus ' ) ( env , ctx ) ;
34
34
35
35
ctx . data = require ( './data' ) ( env , ctx ) ;
36
36
ctx . notifications = require ( './notifications' ) ( env , ctx ) ;
37
37
38
- ctx . heartbeat . on ( 'tick' , function ( tick ) {
38
+ ctx . bus . on ( 'tick' , function ( tick ) {
39
39
console . info ( 'tick' , tick . now ) ;
40
40
ctx . data . update ( function dataUpdated ( ) {
41
- ctx . heartbeat . emit ( 'data-loaded' ) ;
41
+ ctx . bus . emit ( 'data-loaded' ) ;
42
42
} ) ;
43
43
} ) ;
44
44
45
- ctx . heartbeat . on ( 'data-loaded' , function ( ) {
45
+ ctx . bus . on ( 'data-loaded' , function ( ) {
46
46
ctx . notifications . processData ( env , ctx ) ;
47
47
} ) ;
48
48
49
- ctx . heartbeat . uptime ( ) ;
49
+ ctx . bus . uptime ( ) ;
50
50
51
51
next ( ) ;
52
52
} )
Original file line number Diff line number Diff line change 1
-
2
- var es = require ( 'event-stream' ) ;
3
1
var Stream = require ( 'stream' ) ;
4
2
5
- function heartbeat ( env , ctx ) {
3
+ function init ( env , ctx ) {
6
4
var beats = 0 ;
7
5
var started = new Date ( ) ;
8
6
var id ;
9
7
var interval = env . HEARTBEAT || 20000 ;
8
+
9
+ var stream = new Stream ;
10
+
10
11
function ictus ( ) {
11
12
var tick = {
12
13
now : new Date ( )
@@ -18,18 +19,20 @@ function heartbeat (env, ctx) {
18
19
} ;
19
20
return tick ;
20
21
}
22
+
21
23
function repeat ( ) {
22
24
stream . emit ( 'tick' , ictus ( ) ) ;
23
25
}
26
+
24
27
function ender ( ) {
25
28
if ( id ) cancelInterval ( id ) ;
26
29
stream . emit ( 'end' ) ;
27
30
}
28
- var stream = new Stream ;
31
+
29
32
stream . readable = true ;
30
33
stream . uptime = repeat ;
31
34
id = setInterval ( repeat , interval ) ;
32
35
return stream ;
33
36
}
34
- module . exports = heartbeat ;
37
+ module . exports = init ;
35
38
Original file line number Diff line number Diff line change @@ -38,15 +38,15 @@ function init (env, ctx) {
38
38
}
39
39
}
40
40
if ( sendClear ) {
41
- ctx . heartbeat . emit ( 'notification' , { clear : true } ) ;
41
+ ctx . bus . emit ( 'notification' , { clear : true } ) ;
42
42
console . info ( 'emitted notification clear' ) ;
43
43
}
44
44
}
45
45
46
46
function emitAlarm ( type ) {
47
47
var alarm = alarms [ type ] ;
48
48
if ( ctx . data . lastUpdated > alarm . lastAckTime + alarm . silenceTime ) {
49
- ctx . heartbeat . emit ( 'notification' , { type : type } ) ;
49
+ ctx . bus . emit ( 'notification' , { type : type } ) ;
50
50
alarm . lastEmitTime = ctx . data . lastUpdated ;
51
51
console . info ( 'emitted notification:' + type ) ;
52
52
} else {
Original file line number Diff line number Diff line change @@ -60,11 +60,11 @@ bootevent(env).boot(function booted (ctx) {
60
60
///////////////////////////////////////////////////
61
61
var websocket = require ( './lib/websocket' ) ( env , ctx , server ) ;
62
62
63
- ctx . heartbeat . on ( 'data-loaded' , function ( ) {
63
+ ctx . bus . on ( 'data-loaded' , function ( ) {
64
64
websocket . processData ( ) ;
65
65
} ) ;
66
66
67
- ctx . heartbeat . on ( 'notification' , function ( info ) {
67
+ ctx . bus . on ( 'notification' , function ( info ) {
68
68
websocket . emitNotification ( info ) ;
69
69
} ) ;
70
70
You can’t perform that action at this time.
0 commit comments