Class: Failbot::JSONBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/failbot/json_backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ JSONBackend

Returns a new instance of JSONBackend.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/failbot/json_backend.rb', line 5

def initialize(host, port)
  if host.to_s.empty?
    raise ArgumentError, "FAILBOT_BACKEND_JSON_HOST setting required."
  end
  if port.to_s.empty?
    raise ArgumentError, "FAILBOT_BACKEND_JSON_PORT setting required."
  end

  @host = host
  @port = port
end

Instance Method Details

#pingObject

Raises:

  • (StandardError)


30
31
32
33
34
35
36
37
38
# File 'lib/failbot/json_backend.rb', line 30

def ping
   response = socket do |s|
    s.send("PING", 0)
    s.close_write
    s.read
  end

  raise StandardError, "failbotd didn't respond to PING, #{response} returned" unless response.start_with?("PONG")
end

#report(data) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/failbot/json_backend.rb', line 17

def report(data)
  payload = data.to_json

  socket do |s|
    s.send(payload, 0)
    nil
  end
end

#reportsObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/failbot/json_backend.rb', line 26

def reports
  raise NotImplementedError
end