$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/.."))

module Buffet
  class RemoteRunner
    def initialize
      @lock = Mutex.new
    end

    def run
      @lock.synchronize do
        @someone_running = true

        buffet = Buffet.new(Settings.get["repository"], {:verbose => @verbose})
        buffet.run(@branch, {:skip_setup => false, :dont_run_migrations => false})
        return true
      end

      return false
    end
  end
end

$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/.."))

module Buffet
  class RemoteRunner
    def initialize
      @lock = Mutex.new
      @someone_running = false
    end

    def can_run?
      return !@someone_running
    end
    
    # There's a potential race condition here where if smoeone checks can_run?,
    # determines it to be true, and then someone else races in and calls run
    # first, the first guy will be waiting for ages before Buffet starts and
    # won't know what's going on. The chances of this happening seem pretty
    # small.
    def run
      @lock.synchronize do
        @someone_running = true

        buffet = Buffet.new(Settings.get["repository"], {:verbose => @verbose})
        buffet.run(@branch, {:skip_setup => false, :dont_run_migrations => false})

        @someone_running = false
        return true
      end
    end
  end
end

Allow a check to see if someone is running Buffet.
Allow a check to see if someone is running Buffet.

Interesting to note is that there is a very minor race condition in this
code, documented in the comment in front of `run`. This race is
incredibly unlikely, and will not break functionality at all, so I
haven't prioritized it.
