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 :(.
This commit is contained in:
		
							parent
							
								
									e1c49bd4e8
								
							
						
					
					
						commit
						a277177fb5
					
				
							
								
								
									
										32
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								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"); | ||||
| }) | ||||
| }); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user