lib/chef-workflow/support/scheduler.rb
#
# Start the scheduler. In serial mode this call will block until the whole
# dependency graph is satisfied, or one of the provisions fails, at which
# point an exception will be raised. In parallel mode, this call completes
# immediately, and you should use #wait_for to control main thread flow.
#
# This call also installs a SIGINFO (Ctrl+T in the terminal on macs) and
# SIGUSR2 handler which can be used to get information on the status of
# what's solved and what's working. 
#
# Immediately returns if in threaded mode and the solver is already running.
#
Start the scheduler. In serial mode this call will block until the whole
dependency graph is satisfied, or one of the provisions fails, at which
point an exception will be raised. In parallel mode, this call completes
immediately, and you should use #wait_for to control main thread flow.

This call also installs a SIGINFO (Ctrl+T in the terminal on macs) and
SIGUSR2 handler which can be used to get information on the status of
what's solved and what's working.

Immediately returns if in threaded mode and the solver is already running.
Start the scheduler . In serial mode this call will block until the whole dependency graph is satisfied or one of the provisions fails at which point an exception will be raised . In parallel mode this call completes immediately and you should use #wait_for to control main thread flow . This call also installs a SIGINFO ( Ctrl + T in the terminal on macs ) and SIGUSR2 handler which can be used to get information on the status of what ' s solved and what ' s working . Immediately returns if in threaded mode and the solver is already running .
def run
    return if @solver_thread and !@serial
    handler = lambda do
      p ["solved:", solved]
      p ["working:", @working]
    end
    %w[USR2 INFO].each { |sig| trap(sig, &handler) if Signal.list[sig] }
    queue_runner = lambda do
      run = true
      while run
        ready = []
        if @queue.empty?
          if @serial
            return
          else
            with_timeout { ready << @queue.shift if ready.empty? }
          end
        end
        while !@queue.empty?
          ready << @queue.shift
        end
        ready.each do |r|
          if r
            @solved_mutex.synchronize do
              solved.add(r)
              @working.delete(r)
              vm_working.delete(r)
            end
          else
            run = false
          end
        end
        service_resolved_waiters if run
      end
    end
    if @serial
      service_resolved_waiters
      queue_runner.call
    else
      @solver_thread = Thread.new do
        with_timeout(false) { service_resolved_waiters }
        queue_runner.call
      end
    end
  end
def run return if @solver_thread and ! @serial handler = lambda do p [ "solved:" , solved ] p [ "working:" , @working ] end %w[ USR2 INFO ] . each { | sig | trap ( sig , & handler ) if Signal . list [ sig ] } queue_runner = lambda do run = true while run ready = [ ] if @queue . empty? if @serial return else with_timeout { ready << @queue . shift if ready . empty? } end end while ! @queue . empty? ready << @queue . shift end ready . each do | r | if r @solved_mutex . synchronize do solved . add ( r ) @working . delete ( r ) vm_working . delete ( r ) end else run = false end end service_resolved_waiters if run end end if @serial service_resolved_waiters queue_runner . call else @solver_thread = Thread . new do with_timeout ( false ) { service_resolved_waiters } queue_runner . call end end end
Start the scheduler.
Start the scheduler .
# short circuit if we're not serial and already running