Class: Step::ResourceManager
- Inherits:
-
Object
- Object
- Step::ResourceManager
- Defined in:
- lib/rbbt/workflow/schedule.rb
Defined Under Namespace
Classes: NotEnoughResources
Instance Attribute Summary collapse
-
#cpus ⇒ Object
Returns the value of attribute cpus.
-
#memory ⇒ Object
Returns the value of attribute memory.
Class Method Summary collapse
Instance Method Summary collapse
- #allocate(cpus = nil, memory = nil, &block) ⇒ Object
- #finalize(manager) ⇒ Object
-
#initialize(cpus = nil, memory = nil) ⇒ ResourceManager
constructor
A new instance of ResourceManager.
Constructor Details
#initialize(cpus = nil, memory = nil) ⇒ ResourceManager
Returns a new instance of ResourceManager.
7 8 9 10 11 12 |
# File 'lib/rbbt/workflow/schedule.rb', line 7 def initialize(cpus = nil, memory = nil) @cpus = cpus @memory = memory @sem_file = "ResourceManager-" + rand(10000).to_s @semaphore = RbbtSemaphore.create_semaphore(@sem_file, 1) end |
Instance Attribute Details
#cpus ⇒ Object
Returns the value of attribute cpus.
6 7 8 |
# File 'lib/rbbt/workflow/schedule.rb', line 6 def cpus @cpus end |
#memory ⇒ Object
Returns the value of attribute memory.
6 7 8 |
# File 'lib/rbbt/workflow/schedule.rb', line 6 def memory @memory end |
Class Method Details
.finalize(manager) ⇒ Object
35 36 37 |
# File 'lib/rbbt/workflow/schedule.rb', line 35 def self.finalize(manager) proc { manager.finalize } end |
Instance Method Details
#allocate(cpus = nil, memory = nil, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbbt/workflow/schedule.rb', line 14 def allocate(cpus = nil, memory = nil, &block) RbbtSemaphore.synchronize(@semaphore) do if (@cpus && cpus && @cpus < cups) || (@memory && memory && @memory < memory) raise NotEnoughResources end begin @cpus -= cpus @memory -= memory yield rescue @cpus += cpus @memory += memory end end end |
#finalize(manager) ⇒ Object
31 32 33 |
# File 'lib/rbbt/workflow/schedule.rb', line 31 def finalize(manager) RbbtSemaphore.delete_semaphore(@sem_file) end |