15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/que/connection_pool.rb', line 15
def checkout
@connection_proc.call do |conn|
preexisting = wrapped = current_connection
begin
if preexisting
if preexisting.wrapped_connection.backend_pid != conn.backend_pid
raise Error, "Connection pool is not reentrant! previous: #{preexisting.wrapped_connection.inspect} now: #{conn.inspect}"
end
else
sync do
Que.assert(@checked_out.add?(conn.backend_pid)) do
"Connection pool didn't synchronize access properly! (entrance: #{conn.backend_pid})"
end
end
self.current_connection = wrapped = Connection.wrap(conn)
end
yield(wrapped)
ensure
if preexisting.nil?
self.current_connection = nil
sync do
Que.assert(@checked_out.delete?(conn.backend_pid)) do
"Connection pool didn't synchronize access properly! (exit: #{conn.backend_pid})"
end
end
end
end
end
end
|