Class: GranPulse::Url

Inherits:
Check
  • Object
show all
Defined in:
app/models/gran_pulse/url.rb

Instance Attribute Summary collapse

Attributes inherited from Check

#healthy, #message, #type

Instance Method Summary collapse

Constructor Details

#initializeUrl

Returns a new instance of Url.



5
6
7
# File 'app/models/gran_pulse/url.rb', line 5

def initialize
  self.type = 'url'
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'app/models/gran_pulse/url.rb', line 3

def host
  @host
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'app/models/gran_pulse/url.rb', line 3

def port
  @port
end

Instance Method Details

#perform(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/gran_pulse/url.rb', line 9

def perform params
  self.host = URI.parse(params[:host]).host
  self.port = params[:port] || 80

  begin
    Timeout::timeout(1) do
      begin
        s = TCPSocket.new(host, port)
        s.close
        self.healthy = true
        self.message = 'ok'
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
        self.healthy = false
        self.message = e
      end
    end
  rescue Timeout::Error
    self.healthy = false
    self.message = 'timeout'
  end
  self
end