Class: Katello::Agent::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/agent/dispatcher.rb

Class Method Summary collapse

Class Method Details

.create_histories(host_ids:) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'app/services/katello/agent/dispatcher.rb', line 35

def self.create_histories(host_ids:)
  histories = host_ids.map do |id|
    Katello::Agent::DispatchHistory.new(host_id: id)
  end

  Katello::Agent::DispatchHistory.import(histories)

  histories
end

.delete_client_queue(queue_name:) ⇒ Object



45
46
47
48
# File 'app/services/katello/agent/dispatcher.rb', line 45

def self.delete_client_queue(queue_name:)
  connection = Connection.new
  connection.delete_client_queue(queue_name)
end

.dispatch(message_type, histories, args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/katello/agent/dispatcher.rb', line 17

def self.dispatch(message_type, histories, args)
  message_class = @supported_messages[message_type]
  fail("Unsupported message type: #{message_type}") unless message_class

  messages = histories.map do |history|
    message = message_class.new(**args.merge(consumer_id: history.host.subscription_facet.uuid))
    message.dispatch_history_id = history.id
    message.recipient_address = settings[:client_queue_format] % history.host.subscription_facet.uuid
    message.reply_to = settings[:event_queue_name]
    message
  end

  connection = Connection.new
  connection.send_messages(messages)

  histories
end

.host_queue_name(host) ⇒ Object



50
51
52
53
# File 'app/services/katello/agent/dispatcher.rb', line 50

def self.host_queue_name(host)
  uuid = host.content_facet.uuid
  settings[:client_queue_format] % uuid
end

.register_message(name, klass) ⇒ Object



6
7
8
# File 'app/services/katello/agent/dispatcher.rb', line 6

def self.register_message(name, klass)
  @supported_messages[name] = klass
end

.settingsObject



55
56
57
# File 'app/services/katello/agent/dispatcher.rb', line 55

def self.settings
  SETTINGS[:katello][:agent]
end