From 8a6e5f0a22ff31ef3735f10fa2730c29ba6a912d Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 6 Dec 2016 18:28:25 +0100 Subject: changes: Fix multiple-mail sending; diagnostics --- modules/changes/changes.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'modules/changes/changes.js') diff --git a/modules/changes/changes.js b/modules/changes/changes.js index dde20da..b411471 100644 --- a/modules/changes/changes.js +++ b/modules/changes/changes.js @@ -51,6 +51,7 @@ function scheduleNotify(){ console.log("WARNING: requesting notify schedule when already scheduled"); return; } + console.log("Scheduling notify in "+gsettings.notify.interval/1000+" seconds"); notifyTimeout=setTimeout(notifyTimerFunction,gsettings.notify.interval); } @@ -61,7 +62,12 @@ function notifyTimerFunction(){ } notifyTimeout=setTimeout(notifyTimerFunction,gsettings.notify.interval); console.log("Performing notify"); - performNotify(gsettings.notify,function(){ + performNotify(gsettings.notify,function(err){ + if(err){ + console.log("notifyTimerFunction: error from (presumably) sendMail: "); + console.log(err); + return; + } console.log("Performing cleanup"); performCleanup(); }); @@ -188,16 +194,31 @@ function sendMail(tomails,body,cb){ throw new Error("tomails argument in sendMail not an array!"); } var i; + console.log("Mail to send: "+JSON.stringify(body)); + var proccounter=0; + function decProcCounter(){ + proccounter--; + if(proccounter==0){ + cb(); + } + } + var proc; for(i=0;i started"); proc.stdin.on("error",function(e){ console.log(e); cb(e); }); - proc.stdin.write("To: "+tomails[i]+"\n"+body,function(){ + proc.stdin.write("To: "+tomails[i]+"\n"+body,function(proc,mailtarget){ + console.log("sendmail process for <"+mailtarget+"> write completed"); proc.stdin.end(); - cb(); - }); + }.bind(this,proc,tomails[i])); + proc.on("exit",function(mailtarget,code,signal){ + console.log("sendmail process for <"+mailtarget+"> exited with code "+code); + decProcCounter(); + }.bind(this,tomails[i])); //process will linger till it's finished } } @@ -236,6 +257,7 @@ function performNotify(settings,cb){ } console.log("performNotify: diffs = "+JSON.stringify(diffs)); if(diffs.length!=0){ + console.log("performNotify: settings.to = "+JSON.stringify(settings.to)); sendMail(settings.to,constructMailBody(diffs),cb); } else { cb(); -- cgit v1.2.3-54-g00ecf