Method: ProcessBot::ClientSocket#send_command

Defined in:
lib/process_bot/client_socket.rb

#send_command(data) ⇒ Object

rubocop:disable Metrics/AbcSize



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/process_bot/client_socket.rb', line 22

def send_command(data) # rubocop:disable Metrics/AbcSize
  logger.logs "Sending: #{data}"
  client.puts(JSON.generate(data))
  response_raw = client.gets

  # Happens if process is interrupted
  return :nil if response_raw.nil?

  response = JSON.parse(response_raw)

  return :success if response.fetch("type") == "success"

  if response.fetch("type") == "error"
    error = RuntimeError.new("Command raised an error: #{response.fetch("message")}")
    error.set_backtrace(response.fetch("backtrace") + Thread.current.backtrace)

    raise error
  end
end