summaryrefslogtreecommitdiff
path: root/chef-solr
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2010-06-04 09:42:33 -0700
committerDaniel DeLeo <dan@opscode.com>2010-06-04 09:42:33 -0700
commitc1253b2919e194a9c5b6d960680634688cc30374 (patch)
tree65b63a85cebbb3eb3cedeff6d1d092df7c30f3f3 /chef-solr
parentaac487cd1c4a107a22353280964fcc82cd8bb5e2 (diff)
downloadchef-c1253b2919e194a9c5b6d960680634688cc30374.tar.gz
[CHEF-1270] call to_s on our errors so as not to choke the indexer
Diffstat (limited to 'chef-solr')
-rw-r--r--chef-solr/lib/chef/solr/index_queue_consumer.rb44
1 files changed, 26 insertions, 18 deletions
diff --git a/chef-solr/lib/chef/solr/index_queue_consumer.rb b/chef-solr/lib/chef/solr/index_queue_consumer.rb
index 7cff1d52a1..59f6220308 100644
--- a/chef-solr/lib/chef/solr/index_queue_consumer.rb
+++ b/chef-solr/lib/chef/solr/index_queue_consumer.rb
@@ -40,14 +40,15 @@ class Chef
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
+ begin
+ pitem = payload["item"].to_hash
+ 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
- Chef::Log.info("Indexing #{payload["type"]} #{payload["id"]} from #{payload["database"]} status #{response[:status]}#{response[:status] == :error ? ' ' + response[:error] : ''}")
+ msg = "Indexing #{payload["type"]} #{payload["id"]} from #{payload["database"]} status #{status_message(response)}}"
+ Chef::Log.info(msg)
response
end
@@ -58,18 +59,25 @@ class Chef
end
private
- def generate_response(&block)
- response = {}
- begin
- block.call
- rescue
- response[:status] = :error
- response[:error] = $!
- else
- response[:status] = :ok
- end
- response
+
+ def generate_response(&block)
+ response = {}
+ begin
+ block.call
+ rescue => e
+ response[:status] = :error
+ response[:error] = e
+ else
+ response[:status] = :ok
end
+ response
+ end
+
+ def status_message(response)
+ msg = response[:status].to_s
+ msg << ' ' + response[:error].to_s if response[:status] == :error
+ msg
+ end
end
end