Class: AethernalAgent::OperationPool
- Inherits:
-
Object
- Object
- AethernalAgent::OperationPool
- Defined in:
- lib/aethernal_agent/operation_pool.rb
Instance Attribute Summary collapse
-
#operations ⇒ Object
Returns the value of attribute operations.
Instance Method Summary collapse
- #add_operation(op) ⇒ Object
- #get_operation(uuid) ⇒ Object
-
#initialize(size) ⇒ OperationPool
constructor
A new instance of OperationPool.
- #operation_size ⇒ Object
- #queue_size ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(size) ⇒ OperationPool
Returns a new instance of OperationPool.
4 5 6 7 8 |
# File 'lib/aethernal_agent/operation_pool.rb', line 4 def initialize(size) @size = size @jobs = Queue.new self.operations = {} end |
Instance Attribute Details
#operations ⇒ Object
Returns the value of attribute operations.
2 3 4 |
# File 'lib/aethernal_agent/operation_pool.rb', line 2 def operations @operations end |
Instance Method Details
#add_operation(op) ⇒ Object
33 34 35 36 |
# File 'lib/aethernal_agent/operation_pool.rb', line 33 def add_operation(op) @jobs << op self.operations[op.uuid] = op end |
#get_operation(uuid) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/aethernal_agent/operation_pool.rb', line 38 def get_operation(uuid) op = self.operations[uuid] if !op.nil? && op.is_completed? self.operations.delete(uuid) end return op end |
#operation_size ⇒ Object
29 30 31 |
# File 'lib/aethernal_agent/operation_pool.rb', line 29 def operation_size self.operations.keys.size end |
#queue_size ⇒ Object
25 26 27 |
# File 'lib/aethernal_agent/operation_pool.rb', line 25 def queue_size @jobs.size end |
#start ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/aethernal_agent/operation_pool.rb', line 10 def start @pool = Array.new(@size) do |i| Thread.new do Thread.current[:id] = i catch(:exit) do loop do op = @jobs.pop AethernalAgent.logger.debug("Worker #{i} - Picking up job #{op.uuid}") op.run end end end end end |