@@ -6,11 +6,6 @@ defmodule DBConnection.ConnectionPool do
66
77 You're not supposed to call any functions on this pool directly, but only pass this
88 as the value of the `:pool` option in functions such as `DBConnection.start_link/2`.
9-
10- `disconnect_all/3`, which by default will result in connections being
11- reestablished, can be called periodically to recycle checked-in connections
12- after a maximum lifetime is reached. `Ecto SQL` users may find it at
13- https://hexdocs.pm/ecto_sql/Ecto.Adapters.SQL.html#disconnect_all/3
149 """
1510
1611 use GenServer
@@ -68,7 +63,7 @@ defmodule DBConnection.ConnectionPool do
6863 nil
6964 end
7065
71- ts = { System . monotonic_time ( ) , 0 , max_lifetime }
66+ ts = { nil , max_lifetime }
7267 { :ok , _ } = DBConnection.ConnectionPool.Pool . start_supervised ( queue , mod , opts )
7368 target = Keyword . get ( opts , :queue_target , @ queue_target )
7469 interval = Keyword . get ( opts , :queue_interval , @ queue_interval )
@@ -114,8 +109,8 @@ defmodule DBConnection.ConnectionPool do
114109 end
115110
116111 def handle_call ( { :disconnect_all , interval } , _from , { type , queue , codel , ts } ) do
117- { _ , _ , max_lifetime } = ts
118- ts = { System . monotonic_time ( ) , interval , max_lifetime }
112+ { _ , max_lifetime } = ts
113+ ts = { { System . monotonic_time ( ) , interval } , max_lifetime }
119114 { :reply , :ok , { type , queue , codel , ts } }
120115 end
121116
@@ -165,9 +160,9 @@ defmodule DBConnection.ConnectionPool do
165160
166161 case :ets . info ( holder , :owner ) do
167162 ^ owner ->
168- { time , interval , max_lifetime } = ts
163+ { interval , max_lifetime } = ts
169164
170- if Holder . maybe_disconnect ( holder , time , interval , max_lifetime ) do
165+ if Holder . maybe_disconnect ( holder , interval , max_lifetime ) do
171166 { :noreply , data }
172167 else
173168 handle_checkin ( holder , extra , data )
@@ -239,8 +234,8 @@ defmodule DBConnection.ConnectionPool do
239234 { queued_in_native , holder } = key when queued_in_native <= past_in_native <-
240235 :ets . first ( queue ) do
241236 :ets . delete ( queue , key )
242- { time , _interval , max_lifetime } = ts
243- Holder . maybe_disconnect ( holder , time , 0 , max_lifetime ) or Holder . handle_ping ( holder )
237+ { interval , max_lifetime } = ts
238+ Holder . maybe_disconnect ( holder , interval , max_lifetime ) or Holder . handle_ping ( holder )
244239 drop_idle ( past_in_native , limit - 1 , status , queue , codel , ts )
245240 else
246241 _ ->
0 commit comments