Add hooks to CustomizeConnection to allow users to perform actions on connection checkout/in.#131
Add hooks to CustomizeConnection to allow users to perform actions on connection checkout/in.#131weiznich wants to merge 1 commit intosfackler:masterfrom
CustomizeConnection to allow users to perform actions on connection checkout/in.#131Conversation
connection checkout/in. As discussed in sfackler#130
| /// | ||
| /// If this method returns an error, the connection will be discarded | ||
| #[allow(unused_variables)] | ||
| fn on_checkout(&self, conn: &mut C, is_valid_result: Result<(), E>) -> Result<(), E> { |
There was a problem hiding this comment.
What are the use cases for wanting to interact with is_valid_result here and has_broken below?
There was a problem hiding this comment.
I cannot comment on general use cases here, as that is highly dependent on the ConnectionManager implementation and the underlying connections. Therefore I will only comment on diesel related use cases here.
For on_checkin I see two use cases:
- Allow to checkin transactions with open transactions into the pool, which is sometimes useful for tests. (Diesel marks connections with open transactions as broken)
- Trying to close open transactions and "unbreak" connections here
For on_checkout the main use case would be setting up things before checking out the connection, for example opening a dangling transaction. I've included the result of is_valid here for consistency with on_checkin, but I cannot present a diesel related use case to actually use this result. I would guess that there could be a theoretical connection implementation that allows to reconnect the internal connection if some check has failed.
As discussed in #130
cc @Ten0