mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-19 03:09:16 +00:00
move build log lines parsing to lib distributor
This commit is contained in:
parent
65fde3532a
commit
b34f618adc
@ -100,52 +100,7 @@ exports.init = function(app, callback) {
|
|||||||
buildsResource.clientEmitSync('cancel', {buildId: build.id});
|
buildsResource.clientEmitSync('cancel', {buildId: build.id});
|
||||||
});
|
});
|
||||||
|
|
||||||
var buildLogLineNumbersHash = {},
|
distributor.on('buildLogLines', function(build, lines) {
|
||||||
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;
|
|
||||||
app.dataio.resource('build' + build.id).clientEmitSync(
|
app.dataio.resource('build' + build.id).clientEmitSync(
|
||||||
'data',
|
'data',
|
||||||
{lines: lines}
|
{lines: lines}
|
||||||
|
@ -27,6 +27,9 @@ function Distributor(params) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.projects = params.projects;
|
self.projects = params.projects;
|
||||||
|
|
||||||
|
self.buildLogLineNumbersHash = {},
|
||||||
|
self.lastLinesHash = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Distributor, EventEmitter);
|
inherits(Distributor, EventEmitter);
|
||||||
@ -101,7 +104,7 @@ Distributor.prototype._runNext = function(callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
executor.on('data', function(data) {
|
executor.on('data', function(data) {
|
||||||
self.emit('buildData', build, data);
|
self._onBuildData(build, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
executor.once('scmData', function(scmData) {
|
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() {
|
Distributor.prototype._updateWaitReasons = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
_(self.queue).each(function(item) {
|
_(self.queue).each(function(item) {
|
||||||
|
Loading…
Reference in New Issue
Block a user