Sha256: ee2509719ae30b763ab5517c3c806f6132999fd20181d5dae81154e00949ba5a

Contents?: true

Size: 1.22 KB

Versions: 18

Compression:

Stored size: 1.22 KB

Contents

module Roqua
  module StatusChecks
    # To use this status controller in a Rails application, add a route:
    #
    # get '/status' => 'roqua/status_checks/status#balancer_status'
    #
    # If you want to add more logic to the status controller, extend it:
    #
    # get '/status' => 'status#balancer_status'
    #
    # class StatusController < Roqua::StatusChecks::StatusController
    #   skip_before_action :foo
    #   skip_before_action :bar
    # end
    class StatusController < ActionController::Base
      def balancer_status
        balancer_member = balancer_member?
        db_connected = db_connected?

        http_code = balancer_member && db_connected ? 200 : 503
        status = db_connected ? 'ok' : 'error'

        render json: {status: status, member: balancer_member}, status: http_code
      rescue CheckLoadBalancerMember::InvalidStatus
        render json: {status: "unknown status"}, status: 500
      end

      protected

      def balancer_state_file
        Rails.root.join('config/balancer_state')
      end

      def balancer_member?
        CheckLoadBalancerMember.balancer_member?(balancer_state_file)
      end

      def db_connected?
        CheckDbConnection.connected?
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
roqua-support-0.4.6 lib/roqua/status_checks/status_controller.rb
roqua-support-0.4.5 lib/roqua/status_checks/status_controller.rb
roqua-support-0.4.4 lib/roqua/status_checks/status_controller.rb
roqua-support-0.4.3 lib/roqua/status_checks/status_controller.rb
roqua-support-0.4.2 lib/roqua/status_checks/status_controller.rb
roqua-support-0.4.1 lib/roqua/status_checks/status_controller.rb
roqua-support-0.4.0 lib/roqua/status_checks/status_controller.rb
roqua-support-0.3.5 lib/roqua/status_checks/status_controller.rb
roqua-support-0.3.4 lib/roqua/status_checks/status_controller.rb
roqua-support-0.3.3 lib/roqua/status_checks/status_controller.rb
roqua-support-0.3.2 lib/roqua/status_checks/status_controller.rb
roqua-support-0.3.1 lib/roqua/status_checks/status_controller.rb
roqua-support-0.3.0 lib/roqua/status_checks/status_controller.rb
roqua-support-0.1.34 lib/roqua/status_checks/status_controller.rb
roqua-support-0.1.33 lib/roqua/status_checks/status_controller.rb
roqua-support-0.1.32 lib/roqua/status_checks/status_controller.rb
roqua-support-0.1.31 lib/roqua/status_checks/status_controller.rb
roqua-support-0.1.30 lib/roqua/status_checks/status_controller.rb