From a277177fb54d982a4fbea2d7ea991aacba1ed4c0 Mon Sep 17 00:00:00 2001 From: jkaplon Date: Sun, 29 Nov 2015 22:25:09 -0500 Subject: [PATCH] Fix setInterval timer function to send email if no messages received from device for given time threshold; this was really a bug with switching to the winston logging package; winston was needed since console.log not available outside of docker container; I was naively logging to the debug level which is below the level logged by winston by default :(. --- server.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/server.js b/server.js index 477379a..94dc368 100644 --- a/server.js +++ b/server.js @@ -148,33 +148,27 @@ app.post('/', function(req, res){ }); setInterval(function() { - // This log message not appearing!!! - winston.debug("this message should appear every minute if setInterval is working."); // Check every hour to see if GoodMorning or GoodEvening has gone missing. var deadManQry = "select published_at from Alerts where datetime(published_at) > datetime('now', '-14.5 hours') order by datetime(published_at) limit 1"; db.get(deadManQry, function(err, row){ - if (err !== null) { console.log(err); } - //else if (typeof row == undefined) { - else { // TEST, send the email as long as there's no error. - mailOptions.text = "TEST TEST TEST...It's been too long since the last data transmission from device. \n\n"; - winston.debug("email body would be: " + mailOptions.text); - + if (err !== null) { winston.error(err); } + else if (typeof row == undefined) { + mailOptions.text = "It's been too long since the last data transmission from device. \n\n"; + winston.info(mailOptions.text); // Don't include any other details for now, will need to change DB query to get details on last message received. //mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n'; //mailOptions.text = mailOptions.text + 'Published at, ' + courtsopenUtils.getLocDateFromUTC(pubAt) + ' ' + courtsopenUtils.getLocTimeFromUTC(pubAt) + '\n'; - - //transporter.sendMail(mailOptions, function(error, info){ - //if(error){ - //console.log(error); - //}else{ - //console.log('Message sent: ' + info.response); - //} - //}); + transporter.sendMail(mailOptions, function(error, info){ + if(error){ + console.log(error); + }else{ + console.log('Message sent: ' + info.response); + } + }); } }); -}, 60000); +}, 60 * 60 * 1000); app.listen(3000, function() { - console.log("Started on PORT 3000"); winston.info("Started on PORT 3000"); -}) +});