Skip to content

Commit

Permalink
Fix (most) rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Jan 12, 2022
1 parent 115c413 commit c3f79de
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions config/initializers/rails6_backports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,45 @@ def register_pool(pool, frequency) # :nodoc:
end

private
def spawn_thread(frequency)
Thread.new(frequency) do |t|
running = true
while running
sleep t
@mutex.synchronize do
@pools[frequency].select!(&:weakref_alive?)
@pools[frequency].each do |p|
p.reap
p.flush
rescue WeakRef::RefError
end

if @pools[frequency].empty?
@pools.delete(frequency)
@threads.delete(frequency)
running = false
end

def spawn_thread(frequency)
Thread.new(frequency) do |t|
running = true
while running
sleep t
@mutex.synchronize do
@pools[frequency].select!(&:weakref_alive?)
@pools[frequency].each do |p|
p.reap
p.flush
rescue WeakRef::RefError
end

if @pools[frequency].empty?
@pools.delete(frequency)
@threads.delete(frequency)
running = false
end
end
end
end
end
end

def run
return unless frequency && frequency > 0

self.class.register_pool(pool, frequency)
end
end

def reap
stale_connections = synchronize do
return unless @connections

@connections.select do |conn|
conn.in_use? && !conn.owner.alive?
end.each do |conn|
conn.steal!
end
end.each(&:steal!)
end

stale_connections.each do |conn|
Expand All @@ -79,6 +80,7 @@ def flush(minimum_idle = @idle_timeout)

idle_connections = synchronize do
return unless @connections

@connections.select do |conn|
!conn.in_use? && conn.seconds_idle >= minimum_idle
end.each do |conn|
Expand All @@ -89,9 +91,7 @@ def flush(minimum_idle = @idle_timeout)
end
end

idle_connections.each do |conn|
conn.disconnect!
end
idle_connections.each(&:disconnect!)
end
end
end
Expand Down

0 comments on commit c3f79de

Please sign in to comment.