Commit db1b8d77 authored by Leo Iannacone's avatar Leo Iannacone

added build status watcher - use new module JSONLogger for debomatic

parent 5c6c5d63
......@@ -7,11 +7,17 @@ var express = require('express')
, routes = require('./routes')
, fs = require('fs')
, path = require('path')
, Tail = require('tail').Tail
, config = require('./lib/config.js')
, client = require('./lib/client.js')
, utils = require('./lib/utils.js')
var app = module.exports = express.createServer();
var io = require('socket.io').listen(app);
// status
var status = {}
status.packages = []
// Configuration
app.configure(function(){
......@@ -33,13 +39,13 @@ app.configure('production', function(){
app.use(express.errorHandler());
});
var io = require('socket.io').listen(app);
// Routes
app.get('/', routes.index);
app.get(config.routes.distribution, routes.distribution)
io.sockets.on('connection', function(socket) {
utils.send_distributions(socket)
socket.emit('status', status)
client(socket)
});
......@@ -47,11 +53,39 @@ io.sockets.on('disconnect', function(socket){
});
// watch for new distributions
// watcher on new distributions
fs.watch(config.debomatic.path, { persistent: true }, function (event, fileName) {
utils.send_distributions(io.sockets);
});
// watcher on build_status
status_watcher = new Tail(config.debomatic.jsonfile)
status_watcher.on('line', function(new_content) {
data = null
try {
data = JSON.parse(new_content)
} catch (error) { return }
if (data.status == 'building') {
status.packages.push(data)
}
else if (data.status == 'build-successed'
|| data.status == 'build-failed' )
{
for(i = 0; i < status.packages.length; i++)
{
p = status.packages[i]
if ( p.package == data.package
&& p.distribution == data.distribution )
{
status.packages.splice(i, 1)
break
}
}
}
io.sockets.emit('status-update', data)
})
var server = app.listen(config.port, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
......@@ -88,8 +88,6 @@ function __handler_file_newcontent(event_name, socket, data) {
Client = function (socket) {
utils.send_distributions(socket)
socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data))
return
......
......@@ -5,6 +5,7 @@ config.port = 3000
config.debomatic = {}
config.debomatic.path = '/srv/debomatic-amd64'
config.debomatic.jsonfile = '/var/log/debomatic.json'
config.routes = {}
config.routes.debomatic = '/debomatic'
......
......@@ -129,7 +129,7 @@ utils = {
if (! event_name)
event_name = 'distributions'
return __send_distributions(event_name, socket);
}
},
}
module.exports = utils
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment