code beautifying
This commit is contained in:
parent
19ea878a59
commit
89dff9779a
16
src/main.ts
16
src/main.ts
@ -42,21 +42,12 @@ class MqttMongo extends Events.EventEmitter {
|
|||||||
|
|
||||||
connectToDatabase() {
|
connectToDatabase() {
|
||||||
console.info("About to connect to database")
|
console.info("About to connect to database")
|
||||||
Mongo.MongoClient.connect(this.options['database'],
|
Mongo.MongoClient.connect(this.options['database'])
|
||||||
{
|
|
||||||
// 'server': {
|
|
||||||
// 'reconnectTries': 5,
|
|
||||||
// 'reconnectInterval': 1000,
|
|
||||||
// 'socketOptions': {
|
|
||||||
// 'autoReconnect': false
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
.then(
|
.then(
|
||||||
(tmpDbHandle: Mongo.Db) => {
|
(tmpDbHandle: Mongo.Db) => {
|
||||||
this.dbHandle = tmpDbHandle
|
this.dbHandle = tmpDbHandle
|
||||||
this.dbReady = true;
|
this.dbReady = true;
|
||||||
console.info("Connected to database")
|
console.info("Database connected")
|
||||||
this.dbHandle.on('reconnectFailed', (err : any) => { console.warn(`Error on database ${err}`) })
|
this.dbHandle.on('reconnectFailed', (err : any) => { console.warn(`Error on database ${err}`) })
|
||||||
this.dbHandle.on('reconnect', () => {
|
this.dbHandle.on('reconnect', () => {
|
||||||
console.info("Reconnect on database")
|
console.info("Reconnect on database")
|
||||||
@ -111,7 +102,7 @@ class MqttMongo extends Events.EventEmitter {
|
|||||||
this.mqttClient.on('close', () => { console.warn("MQTT connection closed") })
|
this.mqttClient.on('close', () => { console.warn("MQTT connection closed") })
|
||||||
|
|
||||||
this.mqttClient.on('connect', () => {
|
this.mqttClient.on('connect', () => {
|
||||||
console.info("Connected to MQTT broker")
|
console.info("MQTT broker connected")
|
||||||
this.mqttClient.subscribe(options['topic'])
|
this.mqttClient.subscribe(options['topic'])
|
||||||
this.mqttClient.subscribe('MqttMongo/Command')
|
this.mqttClient.subscribe('MqttMongo/Command')
|
||||||
this.mqttClient.publish('MqttMongo/Status', 'hello, started up')
|
this.mqttClient.publish('MqttMongo/Status', 'hello, started up')
|
||||||
@ -143,6 +134,7 @@ class MqttMongo extends Events.EventEmitter {
|
|||||||
this.emit("reconnectDatabase")
|
this.emit("reconnectDatabase")
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
console.info("Heartbeat timer started")
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown() {
|
shutdown() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user