Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose db socket disconnected/connected events #159

Closed
stalniy opened this issue Mar 5, 2021 · 4 comments · Fixed by #259
Closed

Expose db socket disconnected/connected events #159

stalniy opened this issue Mar 5, 2021 · 4 comments · Fixed by #259
Labels
enhancement New feature or request
Milestone

Comments

@stalniy
Copy link
Contributor

stalniy commented Mar 5, 2021

Motivation

I'd like to know when db connection goes down and gets up at application level. So, I can put my app in emergency mode. For example, if db connection is not available for 5 mins, I could close the app (process.exit) or rely on app caches only and return some additional information for my API clients in response.

Proposed implementation

I propose to add 2 callback functions onconnected and ondisconnected (maybe there is a better way to express this through a single function, like connectionStateChanged but then it will require to call this function when connection becomes idle, so not sure)

@stalniy stalniy changed the title handling of db socket disconnected/connected events Expose db socket disconnected/connected events Mar 5, 2021
@porsager
Copy link
Owner

porsager commented Mar 5, 2021

I think the interesting part here is knowing if all connections are down, but only if the reason was something other than idle_timeout.

So perhaps if the last connection is closed for any other reason than idle_timeout a disconnected event is raised. Would that be suitable for your use case too?

Now perhaps a low level option of listening to every single connection as well could be interesting, but imo not as important.

@stalniy
Copy link
Contributor Author

stalniy commented Mar 16, 2021

Yes, this is exactly what I need

@stalniy
Copy link
Contributor Author

stalniy commented Mar 16, 2021

Maybe we could expose connectionStateChsnge and let the user decide whether he cares about idle state or not.

So, the event in this handler can contain some stats details (amount of idle/disconnected, pool size)

@porsager porsager added the enhancement New feature or request label Mar 23, 2021
@jadbox
Copy link

jadbox commented Apr 10, 2021

Ideally I'd like to have getConnection() exposed so I can reference it directly as needed

@porsager porsager added this to the v2 milestone Sep 20, 2021
@porsager porsager mentioned this issue Jan 11, 2022
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants