summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/changes/changes.js32
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();