Class: ActionSubscriber::Threadpool

Inherits:
Object
  • Object
show all
Defined in:
lib/action_subscriber/threadpool.rb

Class Method Summary collapse

Class Method Details

.busy?Boolean

Class Methods

Returns:

  • (Boolean)


6
7
8
# File 'lib/action_subscriber/threadpool.rb', line 6

def self.busy?
  !ready?
end

.new_pool(name, pool_size = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/action_subscriber/threadpool.rb', line 10

def self.new_pool(name, pool_size = nil)
  fail ArgumentError, "#{name} already exists as a threadpool" if pools.key?(name)
  pool_size ||= ::ActionSubscriber.config.threadpool_size
  pools[name] = ::Lifeguard::InfiniteThreadpool.new(
    :name => name,
    :pool_size => pool_size
  )
end

.pool(which_pool = :default) ⇒ Object



19
20
21
# File 'lib/action_subscriber/threadpool.rb', line 19

def self.pool(which_pool = :default)
  pools[which_pool]
end

.poolsObject



23
24
25
26
27
28
29
30
# File 'lib/action_subscriber/threadpool.rb', line 23

def self.pools
  @pools ||= {
    :default => ::Lifeguard::InfiniteThreadpool.new(
      :name => :default,
      :pool_size => ::ActionSubscriber.config.threadpool_size
    )
  }
end

.ready?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/action_subscriber/threadpool.rb', line 32

def self.ready?
  pools.any? { |_pool_name, pool| !pool.busy? }
end

.ready_sizeObject



36
37
38
39
40
# File 'lib/action_subscriber/threadpool.rb', line 36

def self.ready_size
  pools.inject(0) do |total_ready, (_pool_name, pool)|
    total_ready + [0, pool.pool_size - pool.busy_size].max
  end
end