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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/solr/index_queue_consumer.rb', line 40

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

  response = begin
               pitem = payload["item"].to_hash                  
               generate_response { index.add(payload["id"], payload["database"], payload["type"], pitem) }                  
             rescue NoMethodError
               generate_response() { raise ArgumentError, "Payload item does not respond to :keys or :to_hash, cannot index!" }
             end
  
  Chef::Log.info("Indexing #{payload["type"]} #{payload["id"]} from #{payload["database"]} status #{response[:status]}#{response[:status] == :error ? ' ' + response[:error] : ''}")
  response 
end

#delete(payload) ⇒ Object



55
56
57
58
59
# File 'lib/chef/solr/index_queue_consumer.rb', line 55

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