mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 18:09:15 +00:00
store build data to fs
This commit is contained in:
parent
8652b97543
commit
7742e09bd8
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ static/fonts
|
||||
static/js/libs
|
||||
static/js/templates
|
||||
data/projects/**/workspace
|
||||
data/builds
|
22
app.js
22
app.js
@ -1,9 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var http = require('http');
|
||||
var nodeStatic = require('node-static');
|
||||
var jade = require('jade');
|
||||
var path = require('path');
|
||||
var http = require('http'),
|
||||
nodeStatic = require('node-static'),
|
||||
jade = require('jade'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var staticServer = new nodeStatic.Server('./static');
|
||||
var server = http.createServer(function(req, res, next) {
|
||||
@ -24,12 +25,21 @@ var socketio = require('socket.io')(server);
|
||||
var dataio = require('./dataio')(socketio);
|
||||
|
||||
var app = {
|
||||
// path to root dir (with projects, builds etc)
|
||||
dir: path.join(process.cwd(), 'data'),
|
||||
server: server,
|
||||
dataio: dataio
|
||||
};
|
||||
|
||||
app.config = {};
|
||||
app.config.paths = {};
|
||||
|
||||
// path to root dir (with projects, builds etc)
|
||||
app.config.paths.data = path.join(process.cwd(), 'data');
|
||||
app.config.paths.projects = path.join(app.config.paths.data, 'projects');
|
||||
app.config.paths.builds = path.join(app.config.paths.data, 'builds');
|
||||
fs.exists(app.config.paths.builds, function(exists) {
|
||||
if (!exists) fs.mkdir(app.config.paths.builds);
|
||||
});
|
||||
|
||||
require('./resources')(app);
|
||||
|
||||
app.server.listen(3000);
|
||||
|
@ -5,14 +5,14 @@ var Steppy = require('twostep').Steppy,
|
||||
project = require('../lib/project'),
|
||||
Distributor = require('../lib/distributor').Distributor,
|
||||
db = require('../db'),
|
||||
path = require('path');
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
var projectsDir = path.join(app.dir, 'projects'),
|
||||
projects, projectsHash;
|
||||
var projects, projectsHash;
|
||||
|
||||
project.loadAll(projectsDir, function(err, loadedProjects) {
|
||||
project.loadAll(app.config.paths.projects, function(err, loadedProjects) {
|
||||
if (err) throw err;
|
||||
projects = loadedProjects;
|
||||
projectsHash = _(projects).indexBy(function(project) {
|
||||
@ -39,6 +39,10 @@ module.exports = function(app) {
|
||||
}
|
||||
});
|
||||
|
||||
var getBuildDataFilePath = function(build) {
|
||||
return path.join(app.config.paths.builds, build.id + '.log');
|
||||
};
|
||||
|
||||
distributor.on('buildUpdate', function(build, changes) {
|
||||
var buildsResource = app.dataio.resource('builds');
|
||||
|
||||
@ -46,7 +50,15 @@ module.exports = function(app) {
|
||||
// create resource for build data
|
||||
var buildDataResource = app.dataio.resource('build' + build.id);
|
||||
buildDataResource.on('connection', function(client) {
|
||||
client.emit('sync', 'data', '< collected data >');
|
||||
var callback = this.async();
|
||||
fs.createReadStream(getBuildDataFilePath(build), {encoding: 'utf8'})
|
||||
.on('data', function(data) {
|
||||
client.emit('sync', 'data', data);
|
||||
})
|
||||
.on('end', callback)
|
||||
.on('error', function(err) {
|
||||
console.log(err.stack || err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -55,7 +67,25 @@ module.exports = function(app) {
|
||||
});
|
||||
});
|
||||
|
||||
var writeStreamsHash = {};
|
||||
|
||||
distributor.on('buildData', function(build, data) {
|
||||
if (!/\n$/.test(data)) {
|
||||
data += '\n';
|
||||
}
|
||||
|
||||
var filePath = getBuildDataFilePath(build);
|
||||
writeStreamsHash[filePath] = (
|
||||
writeStreamsHash[filePath] ||
|
||||
fs.createWriteStream(getBuildDataFilePath(build), {encoding: 'utf8'})
|
||||
);
|
||||
// TODO: close ended files
|
||||
writeStreamsHash[filePath]
|
||||
.on('error', function(err) {
|
||||
console.log(err.stack || err);
|
||||
})
|
||||
.write(data);
|
||||
|
||||
app.dataio.resource('build' + build.id).clientEmitSync('data', data);
|
||||
});
|
||||
|
||||
|
@ -24,8 +24,6 @@ define([
|
||||
connect.resource(resourceName).subscribe(function(data) {
|
||||
self.output += data;
|
||||
|
||||
if (!/\n$/.test(self.output)) self.output += '\n';
|
||||
|
||||
self.trigger({
|
||||
buildId: buildId,
|
||||
name: 'Console for build #' + buildId,
|
||||
|
Loading…
Reference in New Issue
Block a user