Sha256: 9bb82921396725f00489a3371e1f3a6b0fe589db3d1bab1f749f6205a0302ecc

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module BigBrother
  class App < Sinatra::Base
    register Sinatra::Synchrony

    set :raise_errors, false

    get "/" do
      [200, <<-CONTENT]
Big Brother: #{BigBrother::VERSION}

Running:
#{BigBrother.clusters.running.map { |cluster| "+ #{cluster}\n" }.join}
Stopped:
#{BigBrother.clusters.stopped.map { |cluster| "- #{cluster}\n" }.join}
      CONTENT
    end

    before "/cluster/:name" do |name|
      @cluster = BigBrother.clusters[name]
      halt 404, "Cluster #{name} not found" if @cluster.nil?
    end

    get "/cluster/:name" do |name|
      @cluster.synchronize! unless @cluster.monitored?
      [200, "Running: #{@cluster.monitored?}"]
    end

    put "/cluster/:name" do |name|
      @cluster.synchronize!
      halt 304 if @cluster.monitored?
      @cluster.start_monitoring!
      [200, "OK"]
    end

    delete "/cluster/:name" do |name|
      halt 304 unless @cluster.monitored?
      @cluster.stop_monitoring!
      [200, "OK"]
    end

    error do
      e = request.env['sinatra.error']

      BigBrother.logger.info "Error: #{e}"
      BigBrother.logger.info e.backtrace.join("\n")

      'Application error'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
big_brother-0.5.0 lib/big_brother/app.rb