tasks: return 404 if task not found

part of #826
This commit is contained in:
Girish Ramakrishnan
2023-05-15 09:50:39 +02:00
parent 9036b272a8
commit 94eb7849fe
3 changed files with 36 additions and 23 deletions

View File

@@ -258,18 +258,20 @@ async function listByTypePaged(type, page, perPage) {
return results;
}
function getLogs(taskId, options) {
assert.strictEqual(typeof taskId, 'string');
async function getLogs(task, options) {
assert.strictEqual(typeof task, 'object');
assert(options && typeof options === 'object');
assert.strictEqual(typeof options.lines, 'number');
assert.strictEqual(typeof options.format, 'string');
assert.strictEqual(typeof options.follow, 'boolean');
debug(`Getting logs for ${taskId}`);
const logFile = `${paths.TASKS_LOG_DIR}/${task.id}.log`;
const cp = logs.tail([`${paths.TASKS_LOG_DIR}/${taskId}.log`], { lines: options.lines, follow: options.follow });
const logStream = new logs.LogStream({ format: options.format || 'json', source: taskId });
if (!task.active && !safe.fs.existsSync(logFile)) throw new BoxError(BoxError.FS_ERROR, 'Log file removed/missing'); // logrotated
const cp = logs.tail([`${paths.TASKS_LOG_DIR}/${task.id}.log`], { lines: options.lines, follow: options.follow });
const logStream = new logs.LogStream({ format: options.format || 'json', source: task.id });
logStream.close = cp.kill.bind(cp, 'SIGKILL'); // hook for caller. closing stream kills the child process
cp.stdout.pipe(logStream);