Fix - reports crashed if the user could not be switched (because mailtrain was not run under root). Now an error is reported.
This commit is contained in:
parent
2ac89f3365
commit
7a08ffa596
4 changed files with 52 additions and 13 deletions
|
@ -1,7 +0,0 @@
|
|||
[log]
|
||||
level="verbose"
|
||||
|
||||
[mysql]
|
||||
user="mailtrain_ro"
|
||||
password="S6Woc9hwWiV9RsWt"
|
||||
|
|
@ -30,6 +30,14 @@ function spawn(callback) {
|
|||
requestCallback.startedCallback(msg.tid);
|
||||
}
|
||||
|
||||
} else if (msg.type === 'process-failed') {
|
||||
let requestCallback = requestCallbacks[msg.tid];
|
||||
if (requestCallback && requestCallback.failedCallback) {
|
||||
requestCallback.failedCallback(msg.msg);
|
||||
}
|
||||
|
||||
delete requestCallbacks[msg.tid];
|
||||
|
||||
} else if (msg.type === 'process-finished') {
|
||||
let requestCallback = requestCallbacks[msg.tid];
|
||||
if (requestCallback && requestCallback.startedCallback) {
|
||||
|
@ -50,10 +58,11 @@ function spawn(callback) {
|
|||
});
|
||||
}
|
||||
|
||||
function start(type, data, startedCallback, finishedCallback) {
|
||||
function start(type, data, startedCallback, finishedCallback, failedCallback) {
|
||||
requestCallbacks[messageTid] = {
|
||||
startedCallback,
|
||||
finishedCallback
|
||||
finishedCallback,
|
||||
failedCallback
|
||||
};
|
||||
|
||||
executorProcess.send({
|
||||
|
|
|
@ -38,13 +38,31 @@ function startWorker(report) {
|
|||
});
|
||||
}
|
||||
|
||||
function onFailed(msg) {
|
||||
runningWorkersCount--;
|
||||
log.error('ReportProcessor', 'Executing worker process for "%s" (tid %s) failed with message "%s". Current worker count is %s.', report.name, workers[report.id], msg, runningWorkersCount);
|
||||
delete workers[report.id];
|
||||
|
||||
const fields = {
|
||||
state: reports.ReportState.FAILED
|
||||
};
|
||||
|
||||
reports.updateFields(report.id, fields, err => {
|
||||
if (err) {
|
||||
log.error('ReportProcessor', err);
|
||||
}
|
||||
|
||||
setImmediate(startWorkers);
|
||||
});
|
||||
}
|
||||
|
||||
const reportData = {
|
||||
id: report.id,
|
||||
name: report.name
|
||||
};
|
||||
|
||||
runningWorkersCount++;
|
||||
executor.start('report-processor-worker', reportData, onStarted, onFinished);
|
||||
executor.start('report-processor-worker', reportData, onStarted, onFinished, onFailed);
|
||||
}
|
||||
|
||||
function startWorkers() {
|
||||
|
|
|
@ -15,26 +15,36 @@ let processes = {};
|
|||
|
||||
function spawnProcess(tid, executable, args, outFile, errFile, cwd, uid, gid) {
|
||||
|
||||
function reportFail(msg) {
|
||||
process.send({
|
||||
type: 'process-failed',
|
||||
msg,
|
||||
tid
|
||||
});
|
||||
}
|
||||
|
||||
fs.open(outFile, 'w', (err, outFd) => {
|
||||
if (err) {
|
||||
log.error('Executor', err);
|
||||
reportFail('Cannot create standard output file.');
|
||||
return;
|
||||
}
|
||||
|
||||
fs.open(errFile, 'w', (err, errFd) => {
|
||||
if (err) {
|
||||
log.error('Executor', err);
|
||||
reportFail('Cannot create standard error file.');
|
||||
return;
|
||||
}
|
||||
|
||||
privilegeHelpers.ensureMailtrainOwner(outFile, (err) => {
|
||||
if (err) {
|
||||
log.info('Executor', 'Cannot change owner of output file of process tid:%s.', tid)
|
||||
log.warn('Executor', 'Cannot change owner of output file of process tid:%s.', tid)
|
||||
}
|
||||
|
||||
privilegeHelpers.ensureMailtrainOwner(errFile, (err) => {
|
||||
if (err) {
|
||||
log.info('Executor', 'Cannot change owner of error output file of process tid:%s.', tid)
|
||||
log.warn('Executor', 'Cannot change owner of error output file of process tid:%s.', tid)
|
||||
}
|
||||
|
||||
const options = {
|
||||
|
@ -45,7 +55,16 @@ function spawnProcess(tid, executable, args, outFile, errFile, cwd, uid, gid) {
|
|||
gid
|
||||
};
|
||||
|
||||
const child = fork(executable, args, options);
|
||||
let child;
|
||||
|
||||
try {
|
||||
child = fork(executable, args, options);
|
||||
} catch (err) {
|
||||
log.error('Executor', 'Cannot start process with tid:%s.', tid);
|
||||
reportFail('Cannot start process.');
|
||||
return;
|
||||
}
|
||||
|
||||
const pid = child.pid;
|
||||
processes[tid] = child;
|
||||
|
||||
|
|
Loading…
Reference in a new issue