diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-02-26 18:44:38 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-02-26 18:44:44 +0300 |
commit | 4bab057343a1d442b77a66a513223d277ee591be (patch) | |
tree | 152420ce8f3ff481a52e80ff3e68233ee3019959 /src | |
parent | 21df0578c506697a13122ff49db62b38cd75b370 (diff) |
jobd/worker: improve error handling for run-manual command
Diffstat (limited to 'src')
-rwxr-xr-x | src/jobd.js | 8 | ||||
-rw-r--r-- | src/worker.js | 12 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/jobd.js b/src/jobd.js index 6567d06..6db98fe 100755 --- a/src/jobd.js +++ b/src/jobd.js @@ -173,10 +173,14 @@ async function onMessage({message, connection}) { jobDoneAwaiters[id] = connection - const {accepted} = await worker.getTasks(null, STATUS_MANUAL, {id}) + const {accepted, error} = await worker.getTasks(null, STATUS_MANUAL, {id}) if (!accepted) { delete jobDoneAwaiters[id] - connection.send(new ResponseMessage().setError('failed to run task')) // would be nice to provide some error... + + let message = 'failed to run task' + if (typeof error === 'string') + message += `: ${error}` + connection.send(new ResponseMessage().setError(message)) } break diff --git a/src/worker.js b/src/worker.js index 3151b40..663a517 100644 --- a/src/worker.js +++ b/src/worker.js @@ -218,6 +218,8 @@ class Worker extends EventEmitter { // get new jobs in transaction await db.beginTransaction() + let error = null + let sqlFields = `id, status, target, slot` let sql if (data.id) { @@ -255,19 +257,22 @@ class Worker extends EventEmitter { id = parseInt(id) if (status !== reqstatus) { - this.logger.warn(`${LOGPREFIX} status = ${status} != ${reqstatus}`) + error = `status = ${status} != ${reqstatus}` + this.logger.warn(`${LOGPREFIX} ${error}`) ignored.push(id) continue } if (!target || this.targets[target] === undefined) { - this.logger.error(`${LOGPREFIX} target '${target}' not found (job id=${id})`) + error = `target '${target}' not found (job id=${id})` + this.logger.error(`${LOGPREFIX} ${error}`) ignored.push(id) continue } if (!slot || this.targets[target].slots[slot] === undefined) { - this.logger.error(`${LOGPREFIX} slot '${slot}' of target '${target}' not found (job id=${id})`) + error = `slot '${slot}' of target '${target}' not found (job id=${id})` + this.logger.error(`${LOGPREFIX} ${error}`) ignored.push(id) continue } @@ -324,6 +329,7 @@ class Worker extends EventEmitter { }) return { + error, rows: results.length, accepted: accepted.length, ignored: ignored.length, |