Class: Elevage::ProvisionerRunQueue
- Inherits:
-
Object
- Object
- Elevage::ProvisionerRunQueue
- Defined in:
- lib/elevage/provisionerrunqueue.rb
Overview
ProvisionerRunQueue
Manage multiple queued and running ‘Elevage::Provisioner` objects/threads
Instance Attribute Summary collapse
-
#build_status_interval ⇒ Object
Returns the value of attribute build_status_interval.
-
#busy_wait_timeout ⇒ Object
Returns the value of attribute busy_wait_timeout.
-
#max_concurrent ⇒ Object
Returns the value of attribute max_concurrent.
-
#provisioners ⇒ Object
Returns the value of attribute provisioners.
-
#running_tasks ⇒ Object
readonly
Returns the value of attribute running_tasks.
Instance Method Summary collapse
-
#initialize ⇒ Elevage::ProvisionerRunQueue
constructor
Create a new run queue.
-
#run ⇒ Object
Process the queue.
-
#to_s ⇒ String
Display a string representation.
Constructor Details
#initialize ⇒ Elevage::ProvisionerRunQueue
Create a new run queue
16 17 18 19 20 21 22 23 |
# File 'lib/elevage/provisionerrunqueue.rb', line 16 def initialize @running_tasks = 0 # We start out with nothing running @max_concurrent = BUILD_CONCURRENT_DEFAULT @busy_wait_timeout = BUILD_CHILD_WAIT_TIMEOUT @build_status_interval = BUILD_STATUS_INTERVAL @provisioners = [] @children = {} end |
Instance Attribute Details
#build_status_interval ⇒ Object
Returns the value of attribute build_status_interval.
12 13 14 |
# File 'lib/elevage/provisionerrunqueue.rb', line 12 def build_status_interval @build_status_interval end |
#busy_wait_timeout ⇒ Object
Returns the value of attribute busy_wait_timeout.
11 12 13 |
# File 'lib/elevage/provisionerrunqueue.rb', line 11 def busy_wait_timeout @busy_wait_timeout end |
#max_concurrent ⇒ Object
Returns the value of attribute max_concurrent.
10 11 12 |
# File 'lib/elevage/provisionerrunqueue.rb', line 10 def max_concurrent @max_concurrent end |
#provisioners ⇒ Object
Returns the value of attribute provisioners.
9 10 11 |
# File 'lib/elevage/provisionerrunqueue.rb', line 9 def provisioners @provisioners end |
#running_tasks ⇒ Object (readonly)
Returns the value of attribute running_tasks.
8 9 10 |
# File 'lib/elevage/provisionerrunqueue.rb', line 8 def running_tasks @running_tasks end |
Instance Method Details
#run ⇒ Object
Process the queue
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/elevage/provisionerrunqueue.rb', line 28 def run puts "#{Time.now} [#{$$}]: Provisioning started." @provisioners.each do |provisioner| # Make sure we're not running more jobs than we're allowed wait_for_tasks child_pid = fork do provision_task task: provisioner end @children[child_pid] = provisioner.name @running_tasks += 1 end # Hang around until we collect all the rest of the children wait_for_tasks state: :collect puts "#{Time.now} [#{$$}]: Provisioning completed." end |
#to_s ⇒ String
Display a string representation
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/elevage/provisionerrunqueue.rb', line 49 def to_s puts "Running Tasks: #{@running_tasks}" puts "Max Concurrency: #{@max_concurrent}" puts "Wait status interval: #{@build_status_interval}" puts 'Current Child processes:' @children.each do |pid, name| puts " - [#{pid}]: #{name}" end puts 'Queued Provisioners:' @provisioners.each do |provisioner| puts " - #{provisioner.name}" end end |