refactor tail invokation into logtail.sh
This commit is contained in:
18
src/tasks.js
18
src/tasks.js
@@ -46,12 +46,11 @@ const assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
database = require('./database.js'),
|
||||
debug = require('debug')('box:tasks'),
|
||||
LogStream = require('./log-stream.js'),
|
||||
logs = require('./logs.js'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
shell = require('./shell.js'),
|
||||
spawn = require('child_process').spawn,
|
||||
_ = require('underscore');
|
||||
|
||||
let gTasks = {}; // indexed by task id
|
||||
@@ -269,19 +268,8 @@ function getLogs(taskId, options) {
|
||||
|
||||
debug(`Getting logs for ${taskId}`);
|
||||
|
||||
const lines = options.lines === -1 ? '+1' : options.lines,
|
||||
format = options.format || 'json',
|
||||
follow = options.follow;
|
||||
|
||||
const cmd = '/usr/bin/tail';
|
||||
let args = [ '--lines=' + lines ];
|
||||
|
||||
if (follow) args.push('--follow', '--retry', '--quiet'); // same as -F. to make it work if file doesn't exist, --quiet to not output file headers, which are no logs
|
||||
args.push(`${paths.TASKS_LOG_DIR}/${taskId}.log`);
|
||||
|
||||
const cp = spawn(cmd, args);
|
||||
|
||||
const logStream = new LogStream({ format, source: taskId });
|
||||
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 });
|
||||
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