diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-12-06 18:28:25 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-12-06 18:28:25 +0100 |
commit | 8a6e5f0a22ff31ef3735f10fa2730c29ba6a912d (patch) | |
tree | db869b5ca506117a68b23d73e8c779d7035bef04 /modules/changes | |
parent | 32e5008c18bed355e5a885c9a8582e8f92e5da0f (diff) |
changes: Fix multiple-mail sending; diagnostics
Diffstat (limited to 'modules/changes')
-rw-r--r-- | modules/changes/changes.js | 32 |
1 files changed, 27 insertions, 5 deletions
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<tomails.length;i++){ - var proc=child_process.spawn("sendmail",[tomails[i]],{stdio:["pipe",process.stdout,process.stderr]}); + proc=child_process.spawn("sendmail",[tomails[i]],{stdio:["pipe",process.stdout,process.stderr]}); + proccounter++; + console.log("sendmail process for <"+tomails[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(); |