viewmodel
Advanced tools
Comparing version 1.5.8 to 1.5.9
@@ -21,3 +21,4 @@ 'use strict'; | ||
port: 27017, | ||
dbName: 'context' | ||
dbName: 'context'//, | ||
// heartbeat: 60 * 1000 | ||
}; | ||
@@ -67,2 +68,3 @@ | ||
self.emit('disconnect'); | ||
self.stopHeartbeat(); | ||
}); | ||
@@ -79,2 +81,6 @@ | ||
self.emit('connect'); | ||
if (self.options.heartbeat) { | ||
self.startHeartbeat(); | ||
} | ||
} | ||
@@ -96,3 +102,34 @@ if (callback) callback(err, self); | ||
stopHeartbeat: function () { | ||
if (this.heartbeatInterval) { | ||
clearInterval(this.heartbeatInterval); | ||
delete this.heartbeatInterval; | ||
} | ||
}, | ||
startHeartbeat: function () { | ||
var self = this; | ||
var gracePeriod = Math.round(this.options.heartbeat / 2); | ||
this.heartbeatInterval = setInterval(function () { | ||
var graceTimer = setTimeout(function () { | ||
if (self.heartbeatInterval) { | ||
console.error((new Error ('Heartbeat timeouted after ' + gracePeriod + 'ms')).stack); | ||
self.db.close(function () {}); | ||
} | ||
}, gracePeriod); | ||
self.db.command({ ping: 1 }, function (err) { | ||
if (graceTimer) clearTimeout(graceTimer); | ||
if (err) { | ||
console.error(err.stack || err); | ||
self.db.close(function () {}); | ||
} | ||
}); | ||
}, this.options.heartbeat); | ||
}, | ||
disconnect: function (callback) { | ||
this.stopHeartbeat(); | ||
if (!this.db) { | ||
@@ -99,0 +136,0 @@ if (callback) callback(null); |
{ | ||
"author": "adrai", | ||
"name": "viewmodel", | ||
"version": "1.5.8", | ||
"version": "1.5.9", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -0,1 +1,4 @@ | ||
## [v1.5.9](https://github.com/adrai/node-viewmodel/compare/v1.5.8...v1.5.9) | ||
- mongodb: added optional heartbeat | ||
## [v1.5.8](https://github.com/adrai/node-viewmodel/compare/v1.5.7...v1.5.8) | ||
@@ -2,0 +5,0 @@ - mongodb: do not call ensureIndexes on clear |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104261
2822