Permalink
Browse files

Version 1.0.4, Added Faye transport, see History.md for complete list

  • Loading branch information...
1 parent 10c397d commit 5c1f91e11619b8bd02b9d51aeabb225d0640e239 @straps committed Oct 27, 2011
View
@@ -0,0 +1,3 @@
+COMMIT
+
+node_modules
View
@@ -1,3 +1,10 @@
+1.0.4 / 2011-10-27
+==================
+ * Added Faye transport for notifying real-time changes via websocket
+ * Tests improvements via Makefile (make test)
+ * Readme updated
+ * General bugfix and improvements
+
1.0.3 / 2011-10-26
==================
* Added the filesystem driver and the inotifywait method; filesystem database emulation to have real-time file change notification using inotifywait child_process
View
@@ -0,0 +1,10 @@
+SHELL := /bin/bash
+
+node-command := xargs -n 1 -I file node file
+
+.PHONY : test
+
+test:
+ @find test -name "test-*.js" | $(node-command)
+
+test-all: test
View
@@ -158,7 +158,7 @@ mixed trigger/polling based driver I'm thinking on.
Test cases are home-made and could not be complete or well done, so feel free to fork and improve tests too.
-In any case, you can test the library doing a `node test/test-*` from main directory
+In any case, you can test the library doing a `make test` from main directory
## Installation
View
@@ -39,6 +39,17 @@ var d={
eventEmitter:{
/** if transports contains eventEmitter, this is REQUIRED */
eventEmitter:null
+ },
+ faye:{
+ /** Can be an http server object or an express object, if null faye initialize a
+ it's own http server communicating on specified port */
+ server:null,
+ port:8000,
+ /** Faye mount and timeout, see: http://faye.jcoglan.com/node.html */
+ mount:'/faye',
+ timeout: 45,
+ /** Channel to publish updates on; _TYPE_ is replaced at runtime with insert/update/delete based on type of update */
+ channel:'/dbmon'
}
},
View
@@ -3,7 +3,7 @@ var _=require('underscore')._,
channelDefaults=require('./channelDefaults').channelDefaults;
var dbmon={
- version : '1.0.0'
+ version : '1.0.4'
};
dbmon.channel = function(opts){
@@ -12,10 +12,17 @@ dbmon.channel = function(opts){
opts.monitor='insert,update,delete,truncate';
}
+ //Method deep opts, underscore does not support deep extend
+
+
//Dynamic Transports Init
var transports=[];
_.each(opts.transports.split(','), function(t){
t=t.trim();
+ //underscore does not support deep extend
+ if (channelDefaults.transportsOpts[t]){
+ opts.transportsOpts[t]=_.extend({}, channelDefaults.transportsOpts[t], opts.transportsOpts[t]);
+ }
if (t){
transports.push(require('./transports/'+t+'-transport').init(opts));
}
@@ -26,6 +33,8 @@ dbmon.channel = function(opts){
//Dynamic driver initialization
driver:require('./drivers/'+opts.driver+'-driver').init(opts, transports),
+ transports:transports,
+
stop:function(){
me.driver.stop();
}
@@ -7,6 +7,12 @@ var init=function init(opts){
var nChanges=0;
var inotifywait = spawn('inotifywait', ['-m', '-r', '-q', '--format', '"%e %w%f"', opts.driverOpts[opts.driver].root]);
+ inotifywait.stderr.setEncoding('utf8');
+ inotifywait.stderr.on('data', function (data) {
+ if (/^execvp\(\)/.test(data)) {
+ console.log('ERR: Failed to start inotifywait process.');
+ }
+ });
inotifywait.stdout.on('data', function(data){
data=''+data;
@@ -0,0 +1,29 @@
+//Faye Tranport
+var faye = require('faye'), bayeux;
+var init=function init(opts){
+ console.log('Faye Transport init');
+
+ bayeux = new faye.NodeAdapter({mount: opts.transportsOpts.faye.mount, timeout: opts.transportsOpts.faye.timeout});
+ if (opts.transportsOpts.faye.server){
+ bayeux.attach(opts.transportsOpts.faye.server);
+ }else{
+ bayeux.listen(opts.transportsOpts.faye.port);
+ }
+
+ var rxType=/_TYPE_/g; //compiles only one time
+ var me={
+ notify:function(type, row){
+ var channel=opts.transportsOpts.faye.channel.replace(rxType, type);
+ bayeux.getClient().publish(channel, row);
+ return me;
+ },
+ stop:function(){
+ bayeux.stop();
+ },
+ bayeux:bayeux
+ };
+ return me;
+
+};
+
+module.exports={init:init};
View
@@ -1,11 +1,12 @@
{ "name": "dbmon",
- "version": "1.0.3",
- "description": "Database Monitor Utilities for Real Time Apps",
- "keywords" : ["dbmon", "monitoring", "postgresql", "mysql", "oracle", "polling", "rdbms"],
+ "version": "1.0.4",
+ "description": "Database and Filesystem Monitor Utilities for Real Time Apps",
+ "keywords" : ["dbmon", "monitoring", "postgresql", "mysql", "oracle", "polling", "rdbms", "faye"],
"author": "Strx <f@strx.it>",
"main": "./index.js",
"dependencies": {
- "pg": ">= 0.6.2",
+ "pg": ">= 0.6.0",
+ "faye": ">= 0.6.5",
"step": ">= 0.0.4",
"underscore": ">= 1.2.0"
},
@@ -18,6 +19,6 @@
"url" : "git://github.com/straps/node-dbmon.git"
},
"scripts" : {
- "test" : "node test/test-*"
+ "test" : "make test"
}
}
@@ -0,0 +1,57 @@
+var assert=require('assert'), utils=require('./utils').utils, dbmon=require('../lib/dbmon'),
+ events=require('events'), _=require('underscore')._, fs=require('fs');
+
+var notifications=0,
+ eventEmitter=new events.EventEmitter();
+
+var dir='/tmp/dbmon', path=dir+'/dbmon-test-filesystem.tmp';
+
+try {
+ fs.unlinkSync(path);
+ fs.rmdirSync(dir);
+}catch(e){}
+try {
+ fs.mkdirSync(dir, '777');
+}catch(e){}
+
+
+var channel=dbmon.channel({
+ driver:'filesystem',
+ driverOpts:{
+ filesystem:{
+ root:dir
+ }
+ },
+ method:'inotifywait',
+ transports:'faye',
+ transportsOpts:{
+ faye:{
+ channel:'/dbmon'
+ }
+ }
+});
+
+//Subscribing from server
+channel.transports[0].bayeux.getClient().subscribe('/dbmon', function(row){
+ notifications++;
+ console.log('on channel /dbmon, row='+JSON.stringify(row));
+});
+
+
+setTimeout(function(){
+ console.log('Creating '+path);
+ var f=fs.openSync(path, 'w+'); //fire insert
+
+ fs.writeSync(f, 'testing update'); //fire update
+ fs.closeSync(f);
+ fs.unlinkSync(path); //fire delete
+
+ setTimeout(function(){
+ utils.assertclog(notifications===3, 'Everything is OK', 'Theres Something Wrong, emitted notifications='+notifications);
+
+ channel.stop();
+ process.exit(0);
+
+ }, 100);
+
+}, 500);
@@ -52,4 +52,4 @@ setTimeout(function(){
channel.stop();
}, 100);
-}, 1000);
+}, 500);
View
@@ -31,7 +31,7 @@ Step(
cli:pgcli
}
},
- transports: 'console,eventEmitter',
+ transports: 'eventEmitter',
transportsOpts:{
eventEmitter:{
eventEmitter:eventEmitter

0 comments on commit 5c1f91e

Please sign in to comment.