Permalink
Browse files

minor fixes and logging

  • Loading branch information...
1 parent 5c1f91e commit c744bb773c73677dae1eb5553eb5eb7078581881 @straps committed Nov 2, 2011
View
@@ -84,9 +84,9 @@ and monitor the console when you create/modify/delete files on your home directo
Dbmon is designed to be dynamic and easily extensible; there are 3 main actors to extend it
- - **transports**, in [lib/providers](https://github.com/straps/node-dbmon/tree/master/lib/transports) are the way dbmon notify events. You can use how many tranports you want separating them by comma. The name specified in the options object have to match the name of the file followed by `-tranport.js` in the `transports` foler, like the `console` transport in the example above.
+ - **transports**, in [lib/transports](https://github.com/straps/node-dbmon/tree/master/lib/transports) are the way dbmon notify events. You can use how many tranports you want separating them by comma. The name specified in the options object have to match the name of the file followed by `-tranport.js` in the `transports` foler, like the `console` transport in the example above.
- **providers**, in [lib/providers](https://github.com/straps/node-dbmon/tree/master/lib/providers), have to initialize their method to fetch data and notify transports whene something happen; in most cases (surely for postgresql case) they should only require the `generic-driver` that dynamiccaly instantiate the method and notify transports
- - **methods**, in [lib/providers](https://github.com/straps/node-dbmon/tree/master/lib/methods), are the core of the system; their implementation depends upon the driver and the method specified in the configuration object and their name should respect `DRIVER-METHOD-method.js` convention (ie: postgresql-trigger-method.js). Methods init function return an `EventEmitter` inherited object that notify listeners where data changes firing the event notification chain
+ - **methods**, in [lib/methods](https://github.com/straps/node-dbmon/tree/master/lib/methods), are the core of the system; their implementation depends upon the driver and the method specified in the configuration object and their name should respect `DRIVER-METHOD-method.js` convention (ie: postgresql-trigger-method.js). Methods init function return an `EventEmitter` inherited object that notify listeners where data changes firing the event notification chain
### How To Create a new Transport
@@ -187,8 +187,8 @@ Only for test
## ToDo
- Develop other drivers (MySQL, Oracle, MsSQL, etc...)
- - Develop other transports (Faye, Hook.io, etc..)
- - Write better tests with a single connection, command line parameters and one file per driver/method/transport
+ - Develop other transports (Hook.io, etc..)
+ - Write better unit tests
## License
@@ -7,6 +7,9 @@ var init=function init(opts){
var nChanges=0;
var inotifywait = spawn('inotifywait', ['-m', '-r', '-q', '--format', '"%e %w%f"', opts.driverOpts[opts.driver].root]);
+
+ console.log('Monitoring '+opts.driverOpts[opts.driver].root+' and subfolders');
+
inotifywait.stderr.setEncoding('utf8');
inotifywait.stderr.on('data', function (data) {
if (/^execvp\(\)/.test(data)) {
@@ -8,26 +8,30 @@ var name=function name(table, type){
/** Compose and returns CREATE FUNCTION query */
var triggerFnStr=function triggerFnStr(type, opts){
- var n=name(opts.table, type),
- historyTable=name(opts.table, 'history')+'_table',
- shortType=type.charAt(0),
- rec=type==='delete'?'OLD':'NEW';
- var rv='CREATE OR REPLACE FUNCTION '+n+'_fn() RETURNS trigger AS $$\n'+
- 'DECLARE\n'+
- 'BEGIN\n'+
- (opts.keyfld.name && opts.keyfld.type?
- 'INSERT INTO '+historyTable+' (op, k, oldk)'+
- (type==='truncate'?
- 'VALUES (\''+shortType+'\', NULL, NULL);\n':
- //If UPDATE, save also the old key field value
- 'VALUES (\''+shortType+'\', '+rec+'.'+opts.keyfld.name+', '+(type==='update'?'OLD.'+opts.keyfld.name:rec+'.'+opts.keyfld.name)+');\n'
- )
- :'')+
- 'NOTIFY '+n+';\n'+
- 'RETURN '+rec+';\n'+
- 'END;\n'+
- '$$ LANGUAGE plpgsql;';
- return rv;
+ if (opts.table){
+ var n=name(opts.table, type),
+ historyTable=name(opts.table, 'history')+'_table',
+ shortType=type.charAt(0),
+ rec=type==='delete'?'OLD':'NEW';
+ var rv='CREATE OR REPLACE FUNCTION '+n+'_fn() RETURNS trigger AS $$\n'+
+ 'DECLARE\n'+
+ 'BEGIN\n'+
+ (opts.keyfld.name && opts.keyfld.type?
+ 'INSERT INTO '+historyTable+' (op, k, oldk)'+
+ (type==='truncate'?
+ 'VALUES (\''+shortType+'\', NULL, NULL);\n':
+ //If UPDATE, save also the old key field value
+ 'VALUES (\''+shortType+'\', '+rec+'.'+opts.keyfld.name+', '+(type==='update'?'OLD.'+opts.keyfld.name:rec+'.'+opts.keyfld.name)+');\n'
+ )
+ :'')+
+ 'NOTIFY '+n+';\n'+
+ 'RETURN '+rec+';\n'+
+ 'END;\n'+
+ '$$ LANGUAGE plpgsql;';
+ return rv;
+ }else{
+ console.log('postgresql-trigger-method.js, opts.table REQUIRED');
+ }
};
/** Compose and returns CREATE TRIGGER query */
var triggerStr=function triggerStr(type, opts){
@@ -87,6 +91,7 @@ var init=function init(opts){
if (opts.keyfld.name && opts.keyfld.type){
cli.query(historyTableStr(opts), this);
}else{
+ console.log('postgresql-trigger-method.js, history table not created, opts.keyfld or opts.keytype not valid');
this();
}
},
@@ -117,4 +122,4 @@ var init=function init(opts){
return me;
};
-module.exports={init:init};
+module.exports={init:init};
@@ -1,7 +1,7 @@
//Faye Tranport
var faye = require('faye'), bayeux;
var init=function init(opts){
- console.log('Faye Transport init');
+ console.log('Faye Transport init, mount='+opts.transportsOpts.faye.mount+', channel='+opts.transportsOpts.faye.channel);
bayeux = new faye.NodeAdapter({mount: opts.transportsOpts.faye.mount, timeout: opts.transportsOpts.faye.timeout});
if (opts.transportsOpts.faye.server){
@@ -10,7 +10,7 @@ var init=function init(opts){
bayeux.listen(opts.transportsOpts.faye.port);
}
- var rxType=/_TYPE_/g; //compiles only one time
+ var rxType=/_TYPE_/g; //compiled only the first time
var me={
notify:function(type, row){
var channel=opts.transportsOpts.faye.channel.replace(rxType, type);
@@ -26,4 +26,4 @@ var init=function init(opts){
};
-module.exports={init:init};
+module.exports={init:init};

0 comments on commit c744bb7

Please sign in to comment.