Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 2 additions & 51 deletions bin/mjob
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,6 @@ function jobDataCommon(opts, callback) {
worker: function getJobData(id, cb) {
cb = once(cb);

function handleError(func_err) {
if (func_err.statusCode !== 404) {
cb(func_err);
return;
}

var p = sprintf(JOB_DATA_FMT, opts.user, id, opts.type);
opts.client.get(p, function (err, stream) {
if (err) {
cb(err);
return;
}

var body = '';
stream.setEncoding('utf8');
stream.on('data', function (chunk) {
body += chunk;
});
stream.once('end', function () {
process.stdout.write(body);
cb();
});
});
}

opts.client[opts.func](id, function (err, out) {
if (err) {
handleError(err);
Expand All @@ -216,7 +191,7 @@ function jobDataCommon(opts, callback) {

var body = '';

out.once('error', handleError);
out.once('error', cb);
out.on(opts.watch, function (obj) {
if (opts.func === 'jobErrors') {
body += JSON.stringify(obj) + '\n';
Expand Down Expand Up @@ -401,31 +376,7 @@ function getJobInfo(opts, cb) {
assert.optionalFunc(cb, 'callback');

cb = once(cb);
opts.client.job(opts.id, function (err, job) {
if (err) {
if (err.statusCode !== 404) {
cb(err);
} else {
var p = manta.jobPath(opts.id, opts.user) + '/job.json';
opts.client.get(p, function (_err, stream) {
if (_err) {
cb(_err);
} else {
var body = '';
stream.setEncoding('utf8');
stream.on('data', function (chunk) {
body += chunk;
});
stream.once('end', function () {
cb(null, JSON.parse(body));
});
}
});
}
} else {
cb(null, job);
}
});
opts.client.job(opts.id, cb);
}


Expand Down
36 changes: 31 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ function onResultLineStreamCallback(opts) {

function onResult(err, res) {
if (err) {
if (err.statusCode === 404 && typeof (opts.secondTry) === 'function') {
opts.secondTry();
return;
}
readError(err, res, function () {
log.debug(err, '%s: error', name);
emitter.emit('error', err, res);
Expand Down Expand Up @@ -1931,7 +1935,7 @@ MantaClient.prototype.job = function getJob(j, opts, cb) {
}
assert.func(cb, 'callback');

var _path = getJobPath(j, this.user) + '/live/status';
var _path = getJobPath(j, this.user) + (opts.useArchive ? '/job.json' : '/live/status');
var options = createOptions({
accept: 'application/json',
path: _path
Expand All @@ -1957,6 +1961,11 @@ MantaClient.prototype.job = function getJob(j, opts, cb) {

self.jsonClient.get(options, function (err2, _, __, obj) {
if (err2) {
if (err2.statusCode === 404 && !opts.useArchive) {
opts.useArchive = true;
self.job(j, opts, cb);
return;
}
log.debug(err, 'getJob: failed');
cb(err2);
} else {
Expand Down Expand Up @@ -2318,7 +2327,7 @@ MantaClient.prototype.jobInput = function getJobInput(j, opts, cb) {
}
assert.func(cb, 'callback');

var _path = getJobPath(j, this.user) + '/live/in';
var _path = getJobPath(j, this.user) + (opts.useArchive ? '/in.txt' : '/live/in');
var emitter = new EventEmitter();
var options = createOptions({
accept: 'application/x-json-stream',
Expand Down Expand Up @@ -2349,6 +2358,10 @@ MantaClient.prototype.jobInput = function getJobInput(j, opts, cb) {
log: log,
name: 'jobInput',
onResult: onResultLineStreamCallback({
secondTry: !opts.useArchive && function () {
opts.useArchive = true;
self.jobInput(j, opts, cb);
},
emitter: emitter,
emitCb: function (res, line) {
line = line.replace(/\r?\n$/, '');
Expand Down Expand Up @@ -2395,7 +2408,7 @@ MantaClient.prototype.jobOutput = function getJobOutput(j, opts, cb) {
}
assert.func(cb, 'callback');

var _path = getJobPath(j, this.user) + '/live/out';
var _path = getJobPath(j, this.user) + (opts.useArchive ? '/out.txt' : '/live/out');
var emitter = new EventEmitter();
var options = createOptions({
accept: 'application/x-json-stream',
Expand Down Expand Up @@ -2425,6 +2438,11 @@ MantaClient.prototype.jobOutput = function getJobOutput(j, opts, cb) {
log: log,
name: 'jobOutput',
onResult: onResultLineStreamCallback({
secondTry: !opts.useArchive && function () {
opts.useArchive = true;
opts.headers = {accept: 'text/plain'};
self.jobOutput(j, opts, cb);
},
emitter: emitter,
emitCb: function (res, line) {
line = line.replace(/\r?\n$/, '');
Expand Down Expand Up @@ -2471,7 +2489,7 @@ MantaClient.prototype.jobFailures = function getJobFailures(j, opts, cb) {
}
assert.func(cb, 'callback');

var _path = getJobPath(j, this.user) + '/live/fail';
var _path = getJobPath(j, this.user) + (opts.useArchive ? '/fail.txt' : '/live/fail');
var emitter = new EventEmitter();
var options = createOptions({
accept: 'application/x-json-stream',
Expand Down Expand Up @@ -2501,6 +2519,10 @@ MantaClient.prototype.jobFailures = function getJobFailures(j, opts, cb) {
log: log,
name: 'jobFailures',
onResult: onResultLineStreamCallback({
secondTry: !opts.useArchive && function () {
opts.useArchive = true;
self.jobFailures(j, opts, cb);
},
emitter: emitter,
emitCb: function (res, line) {
line = line.replace(/\r?\n$/, '');
Expand Down Expand Up @@ -2547,7 +2569,7 @@ MantaClient.prototype.jobErrors = function getJobErrors(j, opts, cb) {
}
assert.func(cb, 'callback');

var _path = getJobPath(j, this.user) + '/live/err';
var _path = getJobPath(j, this.user) + (opts.useArchive ? '/err.txt' : '/live/err');
var emitter = new EventEmitter();
var options = createOptions({
accept: 'application/x-json-stream',
Expand Down Expand Up @@ -2588,6 +2610,10 @@ MantaClient.prototype.jobErrors = function getJobErrors(j, opts, cb) {
log: log,
name: 'jobErrors',
onResult: onResultLineStreamCallback({
secondTry: !opts.useArchive && function () {
opts.useArchive = true;
self.jobErrors(j, opts, cb);
},
emitter: emitter,
emitCb: onLine,
log: log,
Expand Down