Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/models/mongo/mongoose-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ mongooseControl.start = function (cb) {
}

mongoose.connect(process.env.MONGO, mongooseOptions, cb)
mongoose.connection.on('disconnected', function () {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, to clean this up a bit can you move this to a helper function?

mongooseControl._handleDisconnect()

uncle bob and I would also be very happy if you broke that down further into

mongooseControl._exitIfNotOpened() {...}

mongooseControl._exitIfConnectionNeverMade () {...}

if (!mongoose.connection._hasOpened) {
log.fatal({message: 'Failed to connect to ' + process.env.MONGO}, 'failed to establish a connection to mongodb')
process.exit(1)
} else {
log.error({message: 'Lost connection to ' + process.env.MONGO})
setTimeout(function () {
if (!mongoose.connection.readyState) {
process.exit(1)
}
}, 10000)
}
})
}

mongooseControl.stop = function (cb) {
Expand Down