shell: add timeout logic and rework error handling
what's important: * if task code ran, it exits with 0. this code is regardless of (error, result) * when it exited cleanly, we will get the values from the database * if task timed out, the box code kills it and it has a flag tracking timedOut. we can ignore exit code in this case. * if task code was stopped, box code will send SIGTERM which ideally it will handle and end with 70. * if task code crashed and it caught the exception, it will return 50 * if task code crashed and node nuked us, it will exit with 1 * if task code was killed with some unhandleabe signal, taskworker.sh will return the signal (9=SIGKILL)
This commit is contained in:
@@ -121,6 +121,17 @@ describe('task', function () {
|
||||
const [error, result] = await safe(tasks.startTask(taskId, {}));
|
||||
if (!error) throw new Error('expecting task to stop');
|
||||
expect(error.message).to.contain('stopped');
|
||||
expect(error.code).to.be(tasks.ESTOPPED);
|
||||
expect(result).to.not.be.ok();
|
||||
});
|
||||
|
||||
it('task timesout', async function () {
|
||||
const taskId = await tasks.add(tasks._TASK_SLEEP, [ 10000 ]);
|
||||
|
||||
const [error, result] = await safe(tasks.startTask(taskId, { timeout: 2000 }));
|
||||
if (!error) throw new Error('expecting task to timeout');
|
||||
expect(error.code).to.be(tasks.ETIMEOUT);
|
||||
expect(error.message).to.contain('timed out');
|
||||
expect(result).to.not.be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user