On Sun, Oct 17, 2021 at 4:49 AM Marcelo <[email protected]>
wrote:

> Hello all,
>
> I'm adding the :connection_expiration extension to a DB instance, but I
> need to change its default expiration time with, for example:
> DB.pool.connection_expiration_timeout = 100
>
> However, this new expiration time is not applied to the initial
> connection, but rather the default value of 14400, and I'm having to resort
> to manually disconnecting and reconnecting:
>
> *DB = Sequel.connect(*
> *  adapter: 'mysql2', host: '127.0.0.1', port: '49153', database: 'my_db',*
> *  user: 'root', password: 'my_pass',*
>
> *  ssl_mode: :disabled,*
> *  extensions: :connection_expiration,*
>
> *)*
>
> *def expiration_times(db)*
> *
> db.pool.instance_variable_get(:@connection_expiration_timestamps).values.map{|v|
> v[1]}.join(', ')*
> *end*
>
> *DB.pool.connection_expiration_timeout = 100*
> *print "Initial values: "*
> *puts expiration_times(DB)*
>
> *DB.disconnect*
> *print "After disconnect: "*
> *puts expiration_times(DB)*
>
> *DB[:users].first*
> *print "After reconnect: "*
> *puts expiration_times(DB)*
>
> *# => Initial values: 14400.0*
> *# => After disconnect: *
> *# => After reconnect: 100.0*
>
> That's still passable, but if I additionally want to enable :preconnect,
> this doesn't work at all, since after DB.disconnect, I'd have to call the
> private method `preconnect` directly.
>
> *DB = Sequel.connect(*
> *  adapter: 'mysql2', host: '127.0.0.1', port: '49153', database: 'my_db',*
> *  user: 'root', password: 'my_pass',*
>
> *  ssl_mode: :disabled,*
> *  preconnect_extensions: :connection_expiration,*
> *  preconnect: true*
> *)*
>
>
> My specific use case is with the connection_expiration extension, but I'm
> interested if there's in general a way to configure the extension prior to
> a connection being established, and especially for preconnections.
>

It doesn't look like there is a way to do what you want currently.  We
would probably need to add an option like :before_preconnect to do so.  I'm
definitely open to that.  If you want to submit a pull request for it,
please do so.  Otherwise, I can probably take care of it before the next
release.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSf98h_87EhsKRgtQ%3D_nC_5wrx5RvTA52wjuBkd9Onj2eQ%40mail.gmail.com.

Reply via email to