Class: RedisClient::Cluster::ConcurrentWorker::OnDemand
- Inherits:
-
Object
- Object
- RedisClient::Cluster::ConcurrentWorker::OnDemand
- Defined in:
- lib/redis_client/cluster/concurrent_worker/on_demand.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(size:) ⇒ OnDemand
constructor
A new instance of OnDemand.
- #inspect ⇒ Object
- #new_group(size:) ⇒ Object
- #push(task) ⇒ Object
Constructor Details
#initialize(size:) ⇒ OnDemand
Returns a new instance of OnDemand.
7 8 9 10 11 |
# File 'lib/redis_client/cluster/concurrent_worker/on_demand.rb', line 7 def initialize(size:) raise ArgumentError, "size must be positive: #{size}" unless size.positive? @q = SizedQueue.new(size) end |
Instance Method Details
#close ⇒ Object
25 26 27 28 29 |
# File 'lib/redis_client/cluster/concurrent_worker/on_demand.rb', line 25 def close @q.clear @q.close nil end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/redis_client/cluster/concurrent_worker/on_demand.rb', line 31 def inspect "#<#{self.class.name} active: #{@q.size}, max: #{@q.max}>" end |
#new_group(size:) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/redis_client/cluster/concurrent_worker/on_demand.rb', line 13 def new_group(size:) ::RedisClient::Cluster::ConcurrentWorker::Group.new( worker: self, queue: SizedQueue.new(size), size: size ) end |
#push(task) ⇒ Object
21 22 23 |
# File 'lib/redis_client/cluster/concurrent_worker/on_demand.rb', line 21 def push(task) @q << spawn_worker(task, @q) end |