12
src/tasks.js
12
src/tasks.js
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user