Commit 4ea3c67b authored by Leo Iannacone's avatar Leo Iannacone

implemented debomatic status

parent ee4d988d
......@@ -72,6 +72,7 @@ server.listen(config.port, config.host, null, function (err) {
client.start();
if (status.length > 0)
client.send_status(status);
client.send_status_debomatic();
});
console.log('Debomatic-webui listening on %s:%d in %s mode', server.address().address, server.address().port, app.settings.env);
......
......@@ -63,12 +63,29 @@ function __watch_distributions(socket) {
});
}
function __watch_pidfile(socket) {
fs.watchFile(config.debomatic.pidfile, {
persistent: false,
interval: 1007
},
function (curr, prev) {
var status_debomatic = {
"running": curr.ino !== 0 // if === 0 means pidfile does not exists
};
try {
socket.emit(socket.emit(config.events.broadcast.status_debomatic, status_debomatic));
} catch (err) {}
});
}
function Broadcaster(sockets, status) {
__watch_status(sockets, status);
__watch_distributions(sockets);
__watch_pidfile(sockets);
return {
};
......
......@@ -181,6 +181,14 @@ function Client(socket) {
this.send_status = function (status) {
socket.emit(_e.status, status);
};
this.send_status_debomatic = function () {
fs.exists(config.debomatic.pidfile, function (exists) {
socket.emit(config.events.broadcast.status_debomatic, {
'running': exists
});
});
};
}
module.exports = Client;
......@@ -67,7 +67,7 @@ config.web.preferences.debug = 0; // debug level - 0 means disabled
// DO NOT TOUCH these ones
config.version = '0.3.1';
config.version = '0.4.0';
// A simple function to quickly have
// get and set strings for client events
......@@ -78,11 +78,18 @@ function _event_get_set(event_name) {
};
}
config.debomatic.pidfile = "/var/run/debomatic-" +
require('crypto')
.createHash('sha256')
.update(config.debomatic.path)
.digest('hex');
config.events = {};
config.events.error = 'error';
config.events.broadcast = {};
config.events.broadcast.distributions = 'distributions';
config.events.broadcast.status_update = 'status_update';
config.events.broadcast.status_debomatic = 'status_debomatic';
config.events.client = {};
config.events.client.distribution_packages = _event_get_set('distribution_packages');
......
......@@ -2,6 +2,7 @@
function Page_Generic() {
var _e = config.events;
var status_debomatic = {};
function __get_status_html_id(status_data) {
var result = 'status-' + status_data.status + '-' + status_data.distribution;
......@@ -73,11 +74,21 @@ function Page_Generic() {
var status = {
set: function (data_status) {
$('#status ul').html('');
if (data_status.length > 0) {
data_status.forEach(function (s) {
status.append(s);
});
if (!data_status) {
if (status_debomatic.running) {
$('#status .idle').show();
$('#status .norunning').hide();
} else {
$('#status .idle').hide();
$('#status .norunning').show();
}
} else {
$('#status ul').html('');
if (data_status.length > 0) {
data_status.forEach(function (s) {
status.append(s);
});
}
}
},
append: function (status_data) {
......@@ -107,8 +118,9 @@ function Page_Generic() {
// and show idle label if necessary.
setTimeout(function () {
li.remove();
if ($('#status li').length === 0)
$('#status .idle').show();
if ($('#status li').length === 0) {
status.set();
}
}, config.status.delay.remove + 2000); // more delay on remove html
}, config.status.delay.remove);
} else if (!status_data.hasOwnProperty('success')) {
......@@ -159,6 +171,12 @@ function Page_Generic() {
status.update(package_status);
});
socket.on(_e.broadcast.status_debomatic, function (socket_status_debomatic) {
debug_socket('received', _e.broadcast.status_debomatic, socket_status_debomatic);
status_debomatic = socket_status_debomatic;
status.set();
});
socket.on(_e.error, function (error) {
console.error('socket > ' + error);
});
......
......@@ -116,6 +116,10 @@ footer {
margin-right: 10px;
}
#status .debomatic {
display: none;
}
#status .packages {
display: inline;
}
......
</div> <!-- #wrapper -->
<footer class="container-fluid">
<small class="copyright pull-right text-muted">
Fork me on <a href="https://github.com/LeoIannacone/debomatic-webui">github</a>
</small>
<div id="status" class="clearfix">
<span class="label label-default">status:</span> <span class="idle text-muted">Idle</span>
<span class="label label-default">status:</span>
<span class="debomatic idle text-muted">Idle</span>
<span class="debomatic norunning text-danger">Not running</span>
<ul class="packages list-inline"></ul>
</div>
</footer>
......
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