Class: Legion::CLI::Doctor::RabbitmqCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/cli/doctor/rabbitmq_check.rb

Constant Summary collapse

DEFAULT_HOST =
'localhost'
DEFAULT_PORT =
5672

Instance Method Summary collapse

Instance Method Details

#nameObject



12
13
14
# File 'lib/legion/cli/doctor/rabbitmq_check.rb', line 12

def name
  'RabbitMQ connection'
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/cli/doctor/rabbitmq_check.rb', line 16

def run
  host = settings_host || DEFAULT_HOST
  port = settings_port || DEFAULT_PORT

  Socket.tcp(host, port, connect_timeout: 3, &:close)
  Result.new(name: name, status: :pass, message: "#{host}:#{port} reachable")
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
  Result.new(
    name:         name,
    status:       :fail,
    message:      "Cannot connect to #{host}:#{port}",
    prescription: 'Start RabbitMQ: `brew services start rabbitmq` or `systemctl start rabbitmq-server`'
  )
rescue LoadError
  Result.new(name: name, status: :skip, message: 'socket not available')
end