mysql-events icon indicating copy to clipboard operation
mysql-events copied to clipboard

More than one .add not working correctly

Open ggabrielCH opened this issue 7 years ago • 7 comments

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.

ggabrielCH avatar Dec 29 '17 20:12 ggabrielCH

yes i have the same problem

ahmedibrahemue avatar Feb 20 '18 15:02 ahmedibrahemue

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

rodrigogs avatar Jun 27 '18 20:06 rodrigogs

@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.

ividrine avatar Jul 11 '18 20:07 ividrine

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 avatar Jul 11 '18 20:07 rodrigogs

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

rodrigogs avatar Jul 11 '18 20:07 rodrigogs

@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.

ividrine avatar Jul 12 '18 15:07 ividrine

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

Thanks for spotting.

rodrigogs avatar Jul 18 '18 04:07 rodrigogs