Skip to content

Commit

Permalink
handling active record connections that are not within the context of…
Browse files Browse the repository at this point in the history
… a request(fiber)
  • Loading branch information
humanzz committed Nov 6, 2008
1 parent 050ce0b commit 7eb5dd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Expand Up @@ -42,7 +42,7 @@ def connect
else # we have a connection pool, we need to recover a connection
@connection.replace_acquired_connection
end
end
end

end

Expand Down
8 changes: 5 additions & 3 deletions lib/never_block/pool/fibered_connection_pool.rb
Expand Up @@ -74,13 +74,17 @@ def all_connections
# Can we create one?
# Wait in the queue then
def acquire(fiber)
# A special case for rails when doing ActiveRecord stuff when not yet
# running in the context of a request (fiber) like in the case of AR
# queries in environment.rb (Root Fiber)
return @connections.first unless fiber[:callbacks]

return fiber[:connection] if fiber[:connection]
conn = if !@connections.empty?
@connections.shift
elsif (@connections.length + @busy_connections.length) < @size
@connection_proc.call
else
# puts ">>>cp: acquire 5"
Fiber.yield @queue << fiber
end

Expand All @@ -94,7 +98,6 @@ def acquire(fiber)

# Give the fiber's connection back to the pool
def release()
# puts ">>>cp: release"
fiber = Fiber.current
if fiber[:connection]
@busy_connections.delete(fiber)
Expand All @@ -106,7 +109,6 @@ def release()
# Check if there are waiting fibers and
# try to process them
def process_queue
# puts ">>>cp: process_queue"
while !@connections.empty? and !@queue.empty?
fiber = @queue.shift
# What is really happening here?
Expand Down

0 comments on commit 7eb5dd9

Please sign in to comment.