Class: Chef::Application::Indexer

Inherits:
Chef::Application show all
Defined in:
lib/chef/application/indexer.rb

Instance Method Summary collapse

Methods inherited from Chef::Application

#configure_chef, #configure_logging, exit!, fatal!, #reconfigure, #run

Constructor Details

#initializeIndexer

Returns a new instance of Indexer.



82
83
84
85
86
# File 'lib/chef/application/indexer.rb', line 82

def initialize
  super

  @chef_search_indexer = nil
end

Instance Method Details

#run_applicationObject

Run the indexer, optionally daemonizing.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/chef/application/indexer.rb', line 99

def run_application
  if Chef::Config[:daemonize]
    Chef::Daemon.daemonize("chef-indexer")
  end

  if Chef::Config[:queue_prefix]
    queue_prefix = Chef::Config[:queue_prefix]
    queue_partial_url = "/queue/#{queue_prefix}/chef"
  else
    queue_partial_url = "/queue/chef"
  end

  loop do
    object, headers = Chef::Queue.receive_msg
    Chef::Log.info("Headers #{headers.inspect}")
    if headers["destination"] == "#{queue_partial_url}/index"
      start_timer = Time.new
      @chef_search_indexer.add(object)
      @chef_search_indexer.commit
      final_timer = Time.new
      Chef::Log.info("Indexed object from #{headers['destination']} in #{final_timer - start_timer} seconds")
    elsif headers["destination"] == "#{queue_partial_url}/remove"
      start_timer = Time.new
      @chef_search_indexer.delete(object)
      @chef_search_indexer.commit
      final_timer = Time.new
      Chef::Log.info("Removed object from #{headers['destination']} in #{final_timer - start_timer} seconds")
    end
  end
rescue SystemExit => e
  raise
rescue Exception => e
  if Chef::Config[:interval]
    Chef::Log.error("#{e.class}")
    Chef::Log.fatal("#{e}\n#{e.backtrace.join("\n")}")
    Chef::Log.fatal("Sleeping for #{Chef::Config[:delay]} seconds before trying again")
    sleep Chef::Config[:delay]
    retry
  else
    raise
  end
end

#setup_applicationObject

Create a new search indexer and connect to the stomp queues



89
90
91
92
93
94
95
96
# File 'lib/chef/application/indexer.rb', line 89

def setup_application
  Chef::Daemon.change_privilege

  @chef_search_indexer = Chef::SearchIndex.new
  Chef::Queue.connect
  Chef::Queue.subscribe(:queue, "index")
  Chef::Queue.subscribe(:queue, "remove")
end