def run
      loop do
        context = @queue.shift
        if context == FINAL_BUNDLE
          break
        elsif context == SHUTDOWN_BUNDLE
          # process shutdown request.
          ShutdownRequest.instance.process
          # continue in queue in the expectation that the decommission bundle will
          # shutdown the instance and its agent normally.
        elsif !context.decommission? && ShutdownRequest.instance.immediately?
          # immediate shutdown preempts any further attempts to run operational
          # scripts but still allows the decommission bundle to run.
          context.audit.update_status("Skipped bundle due to immediate shutdown of #{@thread_name} thread: #{context.payload}")
          # proceed ignoring bundles until final or shutdown are encountered.
        else
          sequence = create_sequence(context)
          sequence.callback { audit_status(sequence) }
          sequence.errback  { audit_status(sequence) }

          # wait until sequence is finished using a ruby mutex conditional.
          # need to synchronize before run to ensure we are waiting before any
          # immediate signalling occurs (under test conditions, etc.).
          @mutex.synchronize do
            @busy = true
            sequence.run
            @sequence_finished.wait(@mutex)
            @pid = nil
            @busy = false
          end
        end
      end
      true
    rescue Exception => e
      Log.error(Log.format("SingleThreadBundleQueue.run failed for #{@thread_name} thread", e, :trace))
    ensure
      # invoke continuation (off of this thread which is going away).
      @mutex.synchronize { @active = false }
      run_continuation
      @thread = nil
    end
def run
      loop do
        context = @queue.shift
        if context == FINAL_BUNDLE
          break
        elsif context == SHUTDOWN_BUNDLE
          # process shutdown request.
          ShutdownRequest.instance.process
          # continue in queue in the expectation that the decommission bundle will
          # shutdown the instance and its agent normally.
        elsif !context.decommission? && ShutdownRequest.instance.immediately?
          # immediate shutdown preempts any further attempts to run operational
          # scripts but still allows the decommission bundle to run.
          context.audit.update_status("Skipped bundle due to immediate shutdown of #{@thread_name} thread: #{context.payload}")
          # proceed ignoring bundles until final or shutdown are encountered.
        else
          sequence = create_sequence(context)
          sequence.callback { audit_status(sequence) }
          sequence.errback  { audit_status(sequence) }

          # wait until sequence is finished using a ruby mutex conditional.
          # need to synchronize before run to ensure we are waiting before any
          # immediate signalling occurs (under test conditions, etc.).
          @mutex.synchronize do
            @busy = true
            sequence.run
            @sequence_finished.wait(@mutex)
            @pid = nil
            @busy = false
          end
        end
      end
      true
    rescue Exception => e
      Log.error(Log.format("SingleThreadBundleQueue.run failed for #{@thread_name} thread", e, :trace))
    ensure
      # invoke continuation (off of this thread which is going away).
      @mutex.synchronize { @active = false }
      run_continuation
      @thread = nil
    end
Run next bundle in the queue if active
 If bundle is FINAL_BUNDLE then call continuation block and deactivate

 === Return
 true:: Always return true