Commit eda15528 authored by Leo Iannacone's avatar Leo Iannacone

back on node-tail module - tailfd seems have strange behaviour on multiple...

back on node-tail module - tailfd seems have strange behaviour on multiple watching - pactched Tail locally in lib/tails.js - no more crashes if file deleted, just warn user via socket
parent 29f55a6d
var config = require('./config.js')
, fs = require('fs')
, tail = require('tailfd').tail
, Tail = require('./tail.js')
// watcher on build_status
function __watch_build_status (socket, status) {
tail(config.debomatic.jsonfile, function(new_content) {
var watcher = new Tail(config.debomatic.jsonfile)
watcher.on('line', function(new_content) {
var data = null
try {
data = JSON.parse(new_content)
......@@ -45,6 +46,9 @@ function __watch_build_status (socket, status) {
socket.emit(config.events.broadcast.status_update, data)
}
})
watcher.on('error', function(msg) {
socket.emit(config.events.error, msg)
})
}
// watcher on new distributions
......
var fs =require('fs')
, Tail = require('tail').Tail
Tail.prototype.watchEvent = function(e) {
var _this = this;
if (e === 'change') {
return fs.stat(this.filename, function(err, stats) {
if (err) {
_this.emit('error', err);
}
if (stats.size < _this.pos) {
_this.pos = stats.size;
}
if (stats.size > _this.pos) {
_this.queue.push({
start: _this.pos,
end: stats.size
});
_this.pos = stats.size;
if (_this.queue.length === 1) {
return _this.internalDispatcher.emit("next");
}
}
});
} else if (e === 'rename') {
this.unwatch();
_this.emit('error', "File " + this.filename + " deleted.");
}
};
Tail.prototype.close = function() {
this.unwatch()
}
module.exports = Tail
\ No newline at end of file
var path = require('path')
, fs = require('fs')
, tail = require('tailfd').tail
, config = require('./config.js')
, Tail = require('./tail.js')
function __errors_handler(from, err, socket) {
if (! socket)
......@@ -93,11 +93,15 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
updater(event_name, socket, data)
})
}
else {
watcher = tail(watch_path,function(new_content, tailInfo) {
else if(stats.isFile()) {
watcher = new Tail(watch_path)
watcher.on('line', function(new_content, tailInfo) {
data.file.new_content = new_content + '\n'
updater(event_name, socket, data)
});
watcher.on('error', function(msg) {
socket.emit(config.events.error, msg);
});
}
socket_watchers[event_name] = watcher
socket.set("watchers", socket_watchers)
......
......@@ -6,7 +6,7 @@
"express": "3.4.8"
, "ejs": ">= 0.0.1"
, "socket.io": "*"
, "tailfd": "*"
, "tail": "*"
}
, "scripts": {
"install": "bash scripts/install.sh"
......
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