def run_loop(&block)
      acquired = false
      begin
        until shutdown_pending?
          # The usual situation
          if relock_every != 0
            i ||= 0
            # 0 % anything is 0, so we always try to get the lock on the first loop.
            if (i %= relock_every) == 0
              acquired = lock_function.call(@name)
            end
          else
            # With relock_every set to 0, only acquire the lock once.
            # Hope you're sure that lock beongs to you.
            acquired ||= lock_function.call(@name)
            i = 0 # no point in incrementing something we don't check.
          end

          yield if acquired

          # Sleep one second at a time so we can quickly respond to
          # shutdown requests.
          sleep_for.times do
            sleep(1) unless shutdown_pending?
          end
          i += 1
        end # loop
      rescue ::Interrupt => ex
        log "shutting down after interrupt: #{ex.class} - #{ex.message}"
        shutdown_soon # Always shut down from an Interrupt, even mid-restart.
        return
      rescue ::Exception => ex
        error "restarting after error: #{ex.class} - #{ex.message}"
        error "backtrace: #{ex.backtrace.join("\n")}"
        restart_soon # Restart if we run into an exception.
      end # begin block
    end
def run_loop(&block)
      acquired = false
      begin
        until shutdown_pending?
          # The usual situation
          if relock_every != 0
            i ||= 0
            # 0 % anything is 0, so we always try to get the lock on the first loop.
            if (i %= relock_every) == 0
              acquired = lock_function.call(@name)
            end
          else
            # With relock_every set to 0, only acquire the lock once.
            # Hope you're sure that lock beongs to you.
            acquired ||= lock_function.call(@name)
            i = 0 # no point in incrementing something we don't check.
          end

          yield if acquired

          # Sleep one second at a time so we can quickly respond to
          # shutdown requests.
          sleep_for.times do
            sleep(1) unless shutdown_pending?
          end
          i += 1
        end # loop
      rescue ::Interrupt => ex
        log "shutting down after interrupt: #{ex.class} - #{ex.message}"
        shutdown_soon # Always shut down from an Interrupt, even mid-restart.
        return
      rescue ::Exception => ex
        error "restarting after error: #{ex.class} - #{ex.message}"
        error "backtrace: #{ex.backtrace.join("\n")}"
        restart_soon # Restart if we run into an exception.
      end # begin block
    end
Run until we receive a shutdown/reload signal,
 or when the worker raises an Interrupt.
 Runs after a fork when Revenant::Daemon is enabled.