Sha256: 3a536b32a2905e7ca5a123321807ae516fc097bdfa082c7362de7eea80f784cf

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

module IsItWorking
  class RsolrCheck
    def initialize(options={})
      @client = options[:client]
      raise ArgumentError.new(":client not specified") unless @client
      @host = @client.uri
      @alias = options[:alias] || @host
    end
    
    def call(status)
      if ping
        status.ok("service active")
        status.info("numDocs: #{luke['numDocs']}")
        status.info("lastModified: #{luke['lastModified']}")
        registry.each do |name, text|
          status.info("#{name} - #{text}")
        end
      else
        status.fail("service down")
      end
    end
    
    def luke
      @luke ||= begin
                  @client.luke(:show => 'schema', :numTerms => 0)['index'] 
                rescue
                  {}
                end
    end

    def registry
      @registry ||= begin
                      resp = Blacklight.solr.get 'admin/registry.jsp', :params => { :wt => 'xml' }
                      doc = Nokogiri::XML resp
                      h = {}
                      doc.xpath('/solr/*').each do |node|
                        next if node.name == "solr-info"
                        h[node.name] = node.text
                      end
                      h
                    rescue
                      {}
                    end
    end

    def ping
      @client.head("admin/ping").response[:status] == 200
    rescue
      false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
is_it_working-cbeer-1.0.13 lib/is_it_working/checks/rsolr_check.rb
is_it_working-cbeer-1.0.12 lib/is_it_working/checks/rsolr_check.rb