Class: IsItWorking::RubydoraCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/is_it_working/checks/rubydora_check.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RubydoraCheck

Returns a new instance of RubydoraCheck.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
# File 'lib/is_it_working/checks/rubydora_check.rb', line 3

def initialize(options={})
  @client = options[:client]
  raise ArgumentError.new(":client not specified") unless @client
  @host = @client.client.url
  @timeout = options[:timeout] || 2
  @alias = options[:alias] || @host
end

Instance Method Details

#call(status) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/is_it_working/checks/rubydora_check.rb', line 11

def call(status)
  begin
    ping
    status.ok("service active")
    ["repositoryName", "repositoryBaseURL", "repositoryVersion"].each do |key|
      status.info("#{key} - #{profile[key]}")
    end
  rescue Errno::ECONNREFUSED
    status.fail("#{@alias} is not accepting connections on port #{@port.inspect}")
  rescue SocketError => e
    status.fail("connection to #{@alias} on port #{@port.inspect} failed with '#{e.message}'")
  rescue Timeout::Error
    status.fail("#{@alias} did not respond on port #{@port.inspect} within #{@timeout} seconds")
  end
end

#pingObject



35
36
37
38
39
40
41
# File 'lib/is_it_working/checks/rubydora_check.rb', line 35

def ping
  timeout(@timeout) do
    s = TCPSocket.new(uri.host, uri.port)
    s.close
  end
  true
end

#profileObject



27
28
29
30
31
32
33
# File 'lib/is_it_working/checks/rubydora_check.rb', line 27

def profile 
  @luke ||= begin
              ActiveFedora::Base.connection_for_pid(0).profile
            rescue
              {}
            end
end

#uriObject



43
44
45
# File 'lib/is_it_working/checks/rubydora_check.rb', line 43

def uri
  URI(@host)
end