Skip to content

Commit 0a397ad

Browse files
committed
Fix global variable
1 parent bdaec11 commit 0a397ad

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

models/ping.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var Ping = new Schema({
1717
error : String
1818
});
1919
Ping.index({ timestamp: -1 });
20+
Ping.index({ check: 1 });
2021
Ping.plugin(require('mongoose-lifecycle'));
2122

2223
Ping.methods.findCheck = function(callback) {
@@ -25,7 +26,7 @@ Ping.methods.findCheck = function(callback) {
2526

2627
Ping.statics.createForCheck = function(status, timestamp, time, check, monitorName, error, callback) {
2728
timestamp = constructor == Date ? timestamp : new Date(parseInt(timestamp));
28-
ping = new this();
29+
var ping = new this();
2930
ping.timestamp = timestamp;
3031
ping.isUp = status;
3132
if (status && check.maxTime) {
@@ -41,12 +42,13 @@ Ping.statics.createForCheck = function(status, timestamp, time, check, monitorNa
4142
ping.downtime = check.interval || 60000;
4243
ping.error = error;
4344
};
44-
ping.save(function(err) {
45-
callback(err, ping);
46-
if (!err) {
47-
check.setLastTest(status, timestamp, error);
48-
check.save();
49-
};
45+
ping.save(function(err1) {
46+
if (err1) return callback(err1);
47+
check.setLastTest(status, timestamp, error);
48+
check.save(function(err2) {
49+
if (err2) return callback(err2);
50+
callback(null, ping);
51+
})
5052
});
5153
}
5254

0 commit comments

Comments
 (0)