def run
      close_requested = false
      shutdown_requested = false
      loop do
        context = @queue.shift
        if context == FINAL_BUNDLE
          if close_thread_queues
            close_requested = true
          else
            break
          end
        elsif context == THREAD_QUEUE_CLOSED_BUNDLE
          unless groom_thread_queues
            if shutdown_requested
              # reset shutdown flag, push shutdown and wait for FINAL_BUNDLE
              shutdown_requested = false
              push_to_thread_queue(SHUTDOWN_BUNDLE)
            else
              break
            end
          end
        elsif context == SHUTDOWN_BUNDLE
          if close_thread_queues
            # defer shutdown until all thread queues close (threads are
            # uninterruptable but the user can always kick the plug out).
            shutdown_requested = true
          else
            # push shutdown and wait for FINAL_BUNDLE
            push_to_thread_queue(SHUTDOWN_BUNDLE)
          end
        elsif !context.decommission? && ShutdownRequest.instance.immediately?
          # immediate shutdown pre-empts any futher attempts to run operational
          # scripts but still allows the decommission bundle to run.
          context.audit.update_status("Skipped bundle due to immediate shutdown: #{context.payload}")
          # proceed ignoring bundles until final or shutdown are encountered.
        else
          push_to_thread_queue(context) unless close_requested
        end
      end
      true
    rescue Exception => e
      Log.error(Log.format("MultiThreadBundleQueue.run failed", e, :trace))
    ensure
      # invoke continuation (off of this thread which is going away).
      @mutex.synchronize { @active = false }
      EM.next_tick { @continuation.call } if @continuation
      @thread = nil
    end
def run
      close_requested = false
      shutdown_requested = false
      loop do
        context = @queue.shift
        if context == FINAL_BUNDLE
          if close_thread_queues
            close_requested = true
          else
            break
          end
        elsif context == THREAD_QUEUE_CLOSED_BUNDLE
          unless groom_thread_queues
            if shutdown_requested
              # reset shutdown flag, push shutdown and wait for FINAL_BUNDLE
              shutdown_requested = false
              push_to_thread_queue(SHUTDOWN_BUNDLE)
            else
              break
            end
          end
        elsif context == SHUTDOWN_BUNDLE
          if close_thread_queues
            # defer shutdown until all thread queues close (threads are
            # uninterruptable but the user can always kick the plug out).
            shutdown_requested = true
          else
            # push shutdown and wait for FINAL_BUNDLE
            push_to_thread_queue(SHUTDOWN_BUNDLE)
          end
        elsif !context.decommission? && ShutdownRequest.instance.immediately?
          # immediate shutdown pre-empts any futher attempts to run operational
          # scripts but still allows the decommission bundle to run.
          context.audit.update_status("Skipped bundle due to immediate shutdown: #{context.payload}")
          # proceed ignoring bundles until final or shutdown are encountered.
        else
          push_to_thread_queue(context) unless close_requested
        end
      end
      true
    rescue Exception => e
      Log.error(Log.format("MultiThreadBundleQueue.run failed", e, :trace))
    ensure
      # invoke continuation (off of this thread which is going away).
      @mutex.synchronize { @active = false }
      EM.next_tick { @continuation.call } if @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