Class: Katello::Agent::ClientMessageHandler

Inherits:
Object
  • Object
show all
Defined in:
app/lib/katello/agent/client_message_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ ClientMessageHandler

Returns a new instance of ClientMessageHandler.



4
5
6
7
8
9
10
11
12
13
14
# File 'app/lib/katello/agent/client_message_handler.rb', line 4

def initialize(message)
  logger.debug("client message: #{message.body}")
  @json = parse_message_json(message)
  dispatch_history_id = @json&.dig(:data, :dispatch_history_id)
  @dispatch_history = Katello::Agent::DispatchHistory.find_by_id(dispatch_history_id)

  unless @dispatch_history
    logger.error("Invalid client message: #{@json}")
    fail("No valid dispatch history in client message")
  end
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/lib/katello/agent/client_message_handler.rb', line 16

def accepted?
  @json[:status] == 'accepted'
end

#handleObject



24
25
26
27
28
29
30
31
32
# File 'app/lib/katello/agent/client_message_handler.rb', line 24

def handle
  @dispatch_history.accepted_at = DateTime.now if accepted?
  @dispatch_history.result = result if result
  @dispatch_history.save!

  if @dispatch_history.dynflow_execution_plan_id && @dispatch_history.dynflow_step_id
    handle_dynflow_event
  end
end

#resultObject



20
21
22
# File 'app/lib/katello/agent/client_message_handler.rb', line 20

def result
  @json.dig(:result, :retval, :details)
end