again improve debug output

This commit is contained in:
Wolfgang Hottgenroth
2017-08-28 12:44:10 +02:00
parent 5b909f5a7a
commit 1cf6c76a7d
2 changed files with 22 additions and 40 deletions

22
dist/mongosave.js vendored
View File

@ -12,42 +12,42 @@ class MongoSave extends CallChain.AAsyncBaseChainItem {
}
func(message, finished) {
if (!this.dbh) {
log.info("Not database connection yet");
log.info("MongoSave: Not database connection yet");
if (!this.connectPending) {
this.connectPending = true;
this.mongoClient.connect(this.url)
.then((db) => {
log.info("Successfully opened MongoDB connect");
log.info("MongoSave: Successfully opened MongoDB connect");
this.dbh = db;
})
.catch((err) => {
log.error(`Failure when opening MongoDB connect: ${err}`);
log.error(`MongoSave: Failure when opening MongoDB connect: ${err}`);
this.dbh = undefined;
});
}
else {
log.info("Connecting to database is pending");
log.info("MongoSave: Connecting to database is pending");
}
}
if (this.dbh) {
log.info("Database handle is available");
log.info("MongoSave: Database handle is available");
let coll = this.dbh.collection("iot");
coll.insertOne(message)
.then((res) => {
log.info(`Successfully wrote one item in database: ${res.insertedId}`);
log.info(`MongoSave: Successfully wrote one item in database: ${res.insertedId}`);
let nextValue = { id: res.insertedId, payload: message };
finished(nextValue);
})
.catch((err) => {
log.error(`Failure when trying to write one item in database: ${err}`);
log.error("Chain interrupted");
log.error(`MongoSave: Failure when trying to write one item in database: ${err}`);
log.error("MongoSave: Chain interrupted");
});
}
else {
log.error(`No database connection yet, drop message ${message}`);
log.error("Chain interrupted");
log.error(`MongoSave: No database connection yet, drop message ${message}`);
log.error("MongoSave: Chain interrupted");
}
log.info(`Returning from ${this.label}`);
log.info(`MongoSave: Returning from ${this.label}`);
}
}
exports.MongoSave = MongoSave;