Last active
May 12, 2020 21:34
-
-
Save jabyrd3/1e11c1bbfde498c0eb18aec3aa5d8648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rabbit = require("rabbit-driver"); | |
class Beemer{ | |
constructor(store, rabbitConfig){ | |
this.store = store; | |
this.loop(); | |
this.mq = new Rabbit(rabbitConfig); | |
} | |
loop(){ | |
// calls itself every 5 seconds to message the return from fetchState | |
this.message(this.fetchState()); | |
this.timeout = setTimeout(loop, 5000) | |
} | |
fetchState(){ | |
// get health from state | |
const state = this.store.getState(); | |
return { | |
health: state.health, | |
nodeid: state.uuid | |
}; | |
} | |
message(state){ | |
// make this actually work | |
this.mq.message(state); | |
} | |
stop(){ | |
clearTimeout(this.timeout); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/supd2/server/index.js b/supd2/server/index.js | |
index 4a05412c0d..88cd09d015 100644 | |
--- a/supd2/server/index.js | |
+++ b/supd2/server/index.js | |
@@ -72,6 +72,8 @@ module.exports = (program, version, config, schema, rw, overrides) => { | |
let store; | |
store = redux.createStore(require('./reducer').reducer()); | |
+ const Beemer = require('./reactors/beemerReactor'); | |
+ const beemInstance = new Beemer(store, rabbitConfig); | |
// server config and compression for bundle size | |
const options = { enableBrotli: true }; | |
@@ -722,6 +724,7 @@ module.exports = (program, version, config, schema, rw, overrides) => { | |
process.on('exit', () => { | |
try { | |
+ beemInstance.stop(); | |
socketServer.close(); | |
kp.nuke(); | |
console.log('INFO: closing'); | |
@@ -733,6 +736,7 @@ module.exports = (program, version, config, schema, rw, overrides) => { | |
process.on('SIGINT', function (err) { | |
// todo: logut store state and info about locks, etc | |
kp.nuke(); | |
+ beemInstance.stop(); | |
socketServer.close() | |
.then(() => | |
process.exit(0)); | |
@@ -740,6 +744,7 @@ module.exports = (program, version, config, schema, rw, overrides) => { | |
process.once('SIGUSR2', function () { | |
kp.nuke(); | |
+ beemInstance.stop(); | |
socketServer.close() | |
.then(() => | |
process.kill(process.pid, 'SIGUSR2')); | |
@@ -747,6 +752,7 @@ module.exports = (program, version, config, schema, rw, overrides) => { | |
process.once('SIGTERM', function () { | |
kp.nuke(); | |
+ beemInstance.stop(); | |
socketServer.close() | |
.then(() => | |
process.kill(process.pid, 'SIGUSR2')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment