Class: Solrizer::Rabbit::QueueIndexWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/solrizer-rabbit/queue_index_worker.rb

Instance Method Summary collapse

Constructor Details

#initializeQueueIndexWorker

Returns a new instance of QueueIndexWorker.



5
6
7
8
9
10
11
# File 'lib/solrizer-rabbit/queue_index_worker.rb', line 5

def initialize
  Thread.current[:carrot] = Carrot.new()#:host=>'mediashelf.eu')
  @q = Carrot.queue(Solrizer::Rabbit.queue_name)

  @buff = BufferedIndexer.new(ActiveFedora::SolrService.instance.conn)
  @stopped = false
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solrizer-rabbit/queue_index_worker.rb', line 18

def run
  indexer = Solrizer::Fedora::Indexer.new
  while !@stopped && msg = @q.pop
    begin
      obj = Solrizer::Fedora::Repository.get_object(msg)
      solr_doc = indexer.create_document( obj )
      @buff.add(solr_doc)
    rescue RSolr::Error::Http, Errno::ECONNREFUSED => exception
      puts "Fatal #{exception.class}, exception see log"
      logger.fatal( "\n\n#{exception.class} (#{exception.message})\n\n")
      logger.flush if logger.respond_to? :flush #Rails logger is flushable, mediashelf-loggable isn't
      exit!
    rescue StandardError => exception
      puts "Caught #{exception.class}, while procesing `#{msg}` see log"
      logger.fatal( "\n\n#{exception.class} (#{exception.message}) while procesing `#{msg}`:\n    " + exception.backtrace.join("\n    ") + "\n\n")
      logger.flush if logger.respond_to? :flush #Rails logger is flushable, mediashelf-loggable isn't
    end
  end
  puts "flushing buffers"
  @buff.flush(true)
  Carrot.stop
  puts "done"
end

#stopObject



13
14
15
16
# File 'lib/solrizer-rabbit/queue_index_worker.rb', line 13

def stop
  puts "finishing writes"
  @stopped=true
end