Class: Katello::Candlepin::MessageHandler

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/candlepin/message_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ MessageHandler

Returns a new instance of MessageHandler.



7
8
9
10
11
# File 'app/services/katello/candlepin/message_handler.rb', line 7

def initialize(message)
  @message = message
  @subscription_facet = ::Katello::Host::SubscriptionFacet.find_by_uuid(consumer_uuid) if consumer_uuid
  @pool = ::Katello::Pool.find_by_cp_id(pool_id) if pool_id
end

Instance Attribute Details

#messageObject (readonly)

Service to handle parsing the messages we receive from candlepin



5
6
7
# File 'app/services/katello/candlepin/message_handler.rb', line 5

def message
  @message
end

#poolObject (readonly)

Service to handle parsing the messages we receive from candlepin



5
6
7
# File 'app/services/katello/candlepin/message_handler.rb', line 5

def pool
  @pool
end

#subscription_facetObject (readonly)

Service to handle parsing the messages we receive from candlepin



5
6
7
# File 'app/services/katello/candlepin/message_handler.rb', line 5

def subscription_facet
  @subscription_facet
end

Instance Method Details

#consumer_uuidObject



41
42
43
# File 'app/services/katello/candlepin/message_handler.rb', line 41

def consumer_uuid
  content['consumerUuid']
end

#contentObject



17
18
19
# File 'app/services/katello/candlepin/message_handler.rb', line 17

def content
  @content ||= JSON.parse(message.content)
end

#delete_poolObject



66
67
68
69
70
# File 'app/services/katello/candlepin/message_handler.rb', line 66

def delete_pool
  if Katello::Pool.where(:cp_id => pool_id).destroy_all.any?
    Rails.logger.info "Deleted Katello::Pool with cp_id=#{pool_id}"
  end
end

#entity_idObject



25
26
27
# File 'app/services/katello/candlepin/message_handler.rb', line 25

def entity_id
  content['entityId']
end

#event_dataObject



21
22
23
# File 'app/services/katello/candlepin/message_handler.rb', line 21

def event_data
  @event_data ||= (data = content['eventData']) ? JSON.parse(data) : {}
end

#import_pool(index_hosts = true) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/services/katello/candlepin/message_handler.rb', line 52

def import_pool(index_hosts = true)
  if pool
    ::Katello::EventQueue.push_event(::Katello::Events::ImportPool::EVENT_TYPE, pool.id)
  else
    begin
      ::Katello::Pool.import_pool(pool_id, index_hosts)
    rescue ActiveRecord::RecordInvalid
      # if we hit this block it's likely that the pool's subscription, product are being created
      # as a result of manifest import/refresh or custom product creation
      Rails.logger.warn("Unable to import pool. It will likely be created by another process.")
    end
  end
end

#pool_idObject



45
46
47
48
49
50
# File 'app/services/katello/candlepin/message_handler.rb', line 45

def pool_id
  case subject
  when 'pool.created', 'pool.deleted'
    content['entityId']
  end
end

#reasonsObject



37
38
39
# File 'app/services/katello/candlepin/message_handler.rb', line 37

def reasons
  event_data['reasons']
end

#statusObject



33
34
35
# File 'app/services/katello/candlepin/message_handler.rb', line 33

def status
  event_data['status']
end

#subjectObject



13
14
15
# File 'app/services/katello/candlepin/message_handler.rb', line 13

def subject
  @message.subject
end

#target_nameObject



29
30
31
# File 'app/services/katello/candlepin/message_handler.rb', line 29

def target_name
  content['targetName']
end