Sha256: 50edd9e474581c553e3a67b34ca5468f97163ec3aba37e3d6820328af364f9a1

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

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

    set :raise_errors, false

    get "/" do
      running, stopped = BigBrother.clusters.values.partition(&:monitored?)

      [200, <<-CONTENT]
Big Brother: #{BigBrother::VERSION}

Running:
#{running.map { |cluster| "+ #{cluster}\n" }.join}
Stopped:
#{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.4.1 lib/big_brother/app.rb