Class: Chef::Solr::IndexQueueConsumer

Inherits:
Object
  • Object
show all
Includes:
IndexQueue::Consumer
Defined in:
lib/chef/solr/index_queue_consumer.rb

Instance Method Summary collapse

Instance Method Details

#add(payload) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef/solr/index_queue_consumer.rb', line 33

def add(payload)
  index = Chef::Solr::Index.new
  Chef::Log.debug("Dequeued item for indexing: #{payload.inspect}")

  begin
    # older producers will send the raw item, and we no longer inflate it
    # to an object.
    pitem = payload["item"].to_hash
    pitem.delete("json_class")
    response = generate_response { index.add(payload["id"], payload["database"], payload["type"], pitem) }                  
  rescue NoMethodError
    response = generate_response() { raise ArgumentError, "Payload item does not respond to :keys or :to_hash, cannot index!" }
  end
  
  msg = "Indexing #{payload["type"]} #{payload["id"]} from #{payload["database"]} status #{status_message(response)}}"
  Chef::Log.info(msg)
  response 
end

#delete(payload) ⇒ Object



52
53
54
55
56
# File 'lib/chef/solr/index_queue_consumer.rb', line 52

def delete(payload)
  response = generate_response { Chef::Solr::Index.new.delete(payload["id"]) }
  Chef::Log.info("Removed #{payload["id"]} from the index")
  response
end