Class: Bixby::AgentHandler

Inherits:
RpcHandler
  • Object
show all
Includes:
Log
Defined in:
lib/bixby-agent/agent_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ AgentHandler

Returns a new instance of AgentHandler.



8
9
10
# File 'lib/bixby-agent/agent_handler.rb', line 8

def initialize(request)
  @request = request
end

Instance Method Details

#handle(json_req) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bixby-agent/agent_handler.rb', line 12

def handle(json_req)

  begin
    cmd_res = Bixby.agent.shell_exec(json_req.params)
    log.debug { cmd_res.to_s + "\n---\n\n\n" }
    return cmd_res.to_json_response

  rescue Exception => ex
    if ex.kind_of? BundleNotFound then
      log.debug(ex.message)
      return JsonResponse.bundle_not_found(ex.message)

    elsif ex.kind_of? CommandNotFound then
      log.debug(ex.message)
      return JsonResponse.command_not_found(ex.message)
    end

    log.error(ex)
    return JsonResponse.new("fail", ex.message, nil, 500)
  end

end