Class: ArchivesSpaceIndexer

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
indexer/app/main.rb

Class Method Summary collapse

Class Method Details

.mainObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'indexer/app/main.rb', line 23

def self.main
  periodic_indexer = PeriodicIndexer.get_indexer
  pui_indexer = PUIIndexer.get_indexer

  threads = []

  Log.info("Starting periodic indexer")
  threads << Thread.new do
    begin
      periodic_indexer.run
    rescue
      Log.error("Unexpected failure in periodic indexer: #{$!}")
    end
  end

  if AppConfig[:pui_indexer_enabled]
    Log.info "Starting PUI indexer"
    threads << Thread.new do
      # Stagger them to encourage them to run at different times
      sleep AppConfig[:solr_indexing_frequency_seconds]

      begin
        pui_indexer.run
      rescue
        Log.error "Unexpected failure in PUI indexer: #{$!}"
      end
    end
  end

  sleep 5

  backend_urls = Atomic.new([])

  threads << Thread.new do
    realtime_indexers = {}

    while true
      begin
        # Once a minute, check to see whether any new backend instances have
        # turned up
        backend_urls.update {|old_urls| AppConfig[:backend_instance_urls]}

        # Start up threads for any backends that don't have one yet
        backend_urls.value.each do |url|
          if !realtime_indexers[url] || !realtime_indexers[url].alive?

            Log.info "Starting realtime indexer for: #{url}"

            realtime_indexers[url] = Thread.new do
              begin
                indexer = RealtimeIndexer.new(url, proc { backend_urls.value.include?(url) })
                indexer.run
              rescue
                Log.error "Realtime indexing error (#{backend_url}): #{$!}"
                sleep 5
              end
            end
          end
        end

        sleep 60
      rescue
        sleep 5
      end
    end
  end


  threads.each {|t| t.join} if java.lang.System.get_property("aspace.devserver")
end