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') ...@@ -7,11 +7,17 @@ var express = require('express')
, routes = require('./routes') , routes = require('./routes')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, Tail = require('tail').Tail
, config = require('./lib/config.js') , config = require('./lib/config.js')
, client = require('./lib/client.js') , client = require('./lib/client.js')
, utils = require('./lib/utils.js') , utils = require('./lib/utils.js')
var app = module.exports = express.createServer(); var app = module.exports = express.createServer();
var io = require('socket.io').listen(app);
// status
var status = {}
status.packages = []
// Configuration // Configuration
app.configure(function(){ app.configure(function(){
...@@ -33,13 +39,13 @@ app.configure('production', function(){ ...@@ -33,13 +39,13 @@ app.configure('production', function(){
app.use(express.errorHandler()); app.use(express.errorHandler());
}); });
var io = require('socket.io').listen(app);
// Routes // Routes
app.get('/', routes.index); app.get('/', routes.index);
app.get(config.routes.distribution, routes.distribution) app.get(config.routes.distribution, routes.distribution)
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
utils.send_distributions(socket)
socket.emit('status', status)
client(socket) client(socket)
}); });
...@@ -47,11 +53,39 @@ io.sockets.on('disconnect', function(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) { fs.watch(config.debomatic.path, { persistent: true }, function (event, fileName) {
utils.send_distributions(io.sockets); 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(){ var server = app.listen(config.port, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); 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) { ...@@ -88,8 +88,6 @@ function __handler_file_newcontent(event_name, socket, data) {
Client = function (socket) { Client = function (socket) {
utils.send_distributions(socket)
socket.on('get_distribution_packages', function (data) { socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data)) if (! utils.check_data_distribution(data))
return return
......
...@@ -5,6 +5,7 @@ config.port = 3000 ...@@ -5,6 +5,7 @@ config.port = 3000
config.debomatic = {} config.debomatic = {}
config.debomatic.path = '/srv/debomatic-amd64' config.debomatic.path = '/srv/debomatic-amd64'
config.debomatic.jsonfile = '/var/log/debomatic.json'
config.routes = {} config.routes = {}
config.routes.debomatic = '/debomatic' config.routes.debomatic = '/debomatic'
......
...@@ -129,7 +129,7 @@ utils = { ...@@ -129,7 +129,7 @@ utils = {
if (! event_name) if (! event_name)
event_name = 'distributions' event_name = 'distributions'
return __send_distributions(event_name, socket); return __send_distributions(event_name, socket);
} },
} }
module.exports = utils 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