spencerlambert / mysql-events

A node meteor package that watches a MySQL database and runs callbacks on matched events.
Other
89 stars 75 forks source link

More than one .add not working correctly #39

Open ggabrielCH opened 6 years ago

ggabrielCH commented 6 years ago

When you create many "watchers" to different tables (with add()), the first watched table works correctly but the other ones stop to work after around 10 minutes.

var MySQLEvents = require('mysql-events');
var mysqlEventWatcher = MySQLEvents({host: 'localhost', user: 'XXX', password: 'YYY'});
var DB = require('./db.js');
var myDB = DB.connection;
...
var watcherEmployees = mysqlEventWatcher.add(
  'db.employees',....
)
var watcherAccounts = mysqlEventWatcher.add(
  'db.accounts',....
)
var watcherBills = mysqlEventWatcher.add(
  'db.bills',....
)

The changes on employees table are always catched, independently of the time there is no action on the table. The changes on accounts and bills tables are not catched anymore if there is no change for around 10 minutes.

If the order of mysqlEventWatcher.add is changed, then it's always the first table watcher who keep working.

ahmedibrahemue commented 6 years ago

yes i have the same problem

rodrigogs commented 6 years ago

https://github.com/rodrigogs/mysql-events

ividrine commented 6 years ago

@rodrigogs your fork doesn't solve any problems here, just has a different api. Multiple triggers only work if they are against the same table in the db. If they are different tables, the triggers seem to be ignored. A quick solution is to just create multiple instances for different tables, but it is very ugly. In reference to #32, I encounter the same problem on your fork. Having access to the connection doesn't really change anything. Keeping the connection alive should be handled in the library, not by the user.

Also, it would be nice if you would enable issues so that I don't have to post here.

rodrigogs commented 6 years ago

What?

Man... you can add as many triggers as you want with my lib with no problem. Did you test it or are you just assuming?

rodrigogs commented 6 years ago

About the issues. Thanks, I didn't realized that it was disabled.

ividrine commented 6 years ago

@rodrigogs

This works:

instance.addTrigger({
        name: 'Name1',
        expression: 'schema.table1',
        statement: MySQLEvents.STATEMENTS.INSERT,
        callback: (event) => { 
                console.log(event)
        }
});

instance.addTrigger({
        name: 'Name2',
        expression: 'schema.table1.column1',
        statement: MySQLEvents.STATEMENTS.UPDATE,
        callback: (event) => { 
                console.log(event)
        }
});

This does not work:

instance.addTrigger({
        name: 'Name1',
        expression: 'schema.table1',
        statement: MySQLEvents.STATEMENTS.INSERT,
        callback: (event) => { 
                console.log(event)
        }
});

instance.addTrigger({
        name: 'Name2',
        expression: 'schema.table1.column1',
        statement: MySQLEvents.STATEMENTS.UPDATE,
        callback: (event) => { 
                console.log(event)
        }
});

// This breaks
instance.addTrigger({
        name: 'Name3',
        expression: 'schema.table2',
        statement: MySQLEvents.STATEMENTS.INSERT,
        callback: (event) => { 
                console.log(event)
        }
});

Again, quick solution is to create a different instance, but its pretty ugly.

rodrigogs commented 6 years ago

@ividrine fixed! https://github.com/rodrigogs/mysql-events/commit/8949adcdb0b4dc18bcb12b167b2a123f53e8905e

Thanks for spotting.