spencerlambert / mysql-events

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

reconnect to mysql when disconnected... #32

Open tvl83 opened 7 years ago

tvl83 commented 7 years ago

Is there a way to detect if I am still connected to mysql and then reconnect if so?

I am using this library to update a firebase live db with information to use in an app. It seems around ~8-9 hours the updates just halt with no errors at all. I can only assume it is, for some reason, disconnecting from the mysqldb.

My initial thought is to run a cronjob every 7hr 55min or so to restart the nodejs app service.

I have a couple things that could be messed up by this even though the restart will be about 1 second long it can potentially cause issues every once in a while so I want to see about just reconnecting once it is disconnected.

Thank you

uksparky commented 7 years ago

+1 for this, I also experience loss of insert events to the db, caused by loss of connection to the db.

tvl83 commented 7 years ago

@uksparky while not the best resolution by any means I used a setInterval for 8 hours to close the connection and restart it and it's been reliable for almost a month now. I have no way of knowing what might be lost in that quick restart, unfortunately

uksparky commented 7 years ago

Thanks for the workaround solution suggestion. Any chance of some example source so I ensure I wrap the right parts of code inside the setInterval. I presume your solution tears down the connections/listeners/etc and doesn't lead to excessive memory usage?

Cheers

On 4 Aug 2017 02:07, "Thomas Le" notifications@github.com wrote:

@uksparky https://github.com/uksparky while not the best resolution by any means I used a setInterval for 8 hours to close the connection and restart it and it's been reliable for almost a month now. I have no way of knowing what might be lost in that quick restart, unfortunately

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spencerlambert/mysql-events/issues/32#issuecomment-320129433, or mute the thread https://github.com/notifications/unsubscribe-auth/ABrPrnSkuVca_BQdCCKp6YN7kE1hk7wHks5sUm6zgaJpZM4OAGxw .

miumax commented 6 years ago

@tvl83 I also got the same issue. But no idea how you "close the connection and restart it" in the setInterval because the connection has done from the mysql-event . Can you please give some example ? that would be big help.

a-k-macdonald commented 6 years ago

@miumax I had this same issue for a while. The code would work nicely and then stop running with no visible sign. I realised, after a while, that I hadn't included the rotate event in the included events for my watcher. Once I set that it worked well.

miumax commented 6 years ago

@a-k-macdonald Can you please give some code example about how to include that rotate event to watcher. That would be great.

a-k-macdonald commented 6 years ago

@miumax I set up my connection as below,

const settings = { includeEvents: ['rotate','tablemap', 'writerows', 'updaterows', 'deleterows'] } var mysqlEventWatcher = MySQLEvents(dsn,settings);

I take the defaults for everything else. I hope that helps.

miumax commented 6 years ago

@a-k-macdonald Big thank, I'll do a try.

miumax commented 6 years ago

@a-k-macdonald No luck. mysqlEventWatcher connection was disconnected after 7,8 hours.

a-k-macdonald commented 6 years ago

@miumax Sorry, I don't know what to suggest then.

rodrigogs commented 6 years ago

Using this lib you can pass a MySQL connection object to the constructor. So you're able to controll your connection out of the box.

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

shubhamdixit863 commented 4 years ago

@a-k-macdonald No luck. mysqlEventWatcher connection was disconnected after 7,8 hours.

Were you able to solve the problem ?