move build log lines parsing to lib distributor

This commit is contained in:
oleg 2016-01-07 00:11:14 +03:00
parent 65fde3532a
commit b34f618adc
2 changed files with 56 additions and 47 deletions

View File

@ -100,52 +100,7 @@ exports.init = function(app, callback) {
buildsResource.clientEmitSync('cancel', {buildId: build.id});
});
var buildLogLineNumbersHash = {},
lastLinesHash = {};
distributor.on('buildData', function(build, data) {
var cleanupText = function(text) {
return text.replace('\r', '');
};
var splittedData = data.split('\n'),
logLineNumber = buildLogLineNumbersHash[build.id] || 0;
lastLinesHash[build.id] = lastLinesHash[build.id] || '';
// if we don't have last line, so we start new line
if (!lastLinesHash[build.id]) {
logLineNumber++;
}
lastLinesHash[build.id] += _(splittedData).first();
var lines = [{
text: cleanupText(lastLinesHash[build.id]),
buildId: build.id,
number: logLineNumber
}];
if (splittedData.length > 1) {
// if we have last '' we have to take all except last
// this shown that string ends with eol
if (_(splittedData).last() === '') {
lastLinesHash[build.id] = '';
splittedData = _(splittedData.slice(1)).initial();
} else {
lastLinesHash[build.id] = _(splittedData).last();
splittedData = _(splittedData).tail();
}
lines = lines.concat(_(splittedData).map(function(line) {
return {
text: cleanupText(line),
buildId: build.id,
number: ++logLineNumber
};
}));
}
buildLogLineNumbersHash[build.id] = logLineNumber;
distributor.on('buildLogLines', function(build, lines) {
app.dataio.resource('build' + build.id).clientEmitSync(
'data',
{lines: lines}

View File

@ -27,6 +27,9 @@ function Distributor(params) {
};
self.projects = params.projects;
self.buildLogLineNumbersHash = {},
self.lastLinesHash = {};
}
inherits(Distributor, EventEmitter);
@ -101,7 +104,7 @@ Distributor.prototype._runNext = function(callback) {
});
executor.on('data', function(data) {
self.emit('buildData', build, data);
self._onBuildData(build, data);
});
executor.once('scmData', function(scmData) {
@ -127,6 +130,57 @@ Distributor.prototype._runNext = function(callback) {
);
};
Distributor.prototype._onBuildData = function(build, data) {
var self = this;
self.emit('buildData', build, data);
var cleanupText = function(text) {
return text.replace('\r', '');
};
var splittedData = data.split('\n'),
logLineNumber = self.buildLogLineNumbersHash[build.id] || 0;
self.lastLinesHash[build.id] = self.lastLinesHash[build.id] || '';
// if we don't have last line, so we start new line
if (!self.lastLinesHash[build.id]) {
logLineNumber++;
}
self.lastLinesHash[build.id] += _(splittedData).first();
var lines = [{
text: cleanupText(self.lastLinesHash[build.id]),
buildId: build.id,
number: logLineNumber
}];
if (splittedData.length > 1) {
// if we have last '' we have to take all except last
// this shown that string ends with eol
if (_(splittedData).last() === '') {
self.lastLinesHash[build.id] = '';
splittedData = _(splittedData.slice(1)).initial();
} else {
self.lastLinesHash[build.id] = _(splittedData).last();
splittedData = _(splittedData).tail();
}
lines = lines.concat(_(splittedData).map(function(line) {
return {
text: cleanupText(line),
buildId: build.id,
number: ++logLineNumber
};
}));
}
self.buildLogLineNumbersHash[build.id] = logLineNumber;
self.emit('buildLogLines', build, lines);
};
Distributor.prototype._updateWaitReasons = function() {
var self = this;
_(self.queue).each(function(item) {