Class: ActionSubscriber::Threadpool
- Inherits:
-
Object
- Object
- ActionSubscriber::Threadpool
- Defined in:
- lib/action_subscriber/threadpool.rb
Class Method Summary collapse
-
.busy? ⇒ Boolean
Class Methods.
- .new_pool(name, pool_size = nil) ⇒ Object
- .pool(which_pool = :default) ⇒ Object
- .pools ⇒ Object
- .ready? ⇒ Boolean
- .ready_size ⇒ Object
Class Method Details
.busy? ⇒ Boolean
Class Methods
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 |
.pools ⇒ Object
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
32 33 34 |
# File 'lib/action_subscriber/threadpool.rb', line 32 def self.ready? pools.any? { |_pool_name, pool| !pool.busy? } end |
.ready_size ⇒ Object
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 |