-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
35 lines (32 loc) · 1019 Bytes
/
main.rb
File metadata and controls
35 lines (32 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'benchmark'
require 'optparse'
require_relative 'db/document_datastore'
require_relative 'db/sample_document_datastore'
require_relative 'indexer'
require_relative 'log/log'
options = {:batch => 250}
OptionParser.new do |opt|
opt.on('--env ENV', 'PROD or DEV') { |o| options[:env] = o }
opt.on('-b', '--batch_size BATCH', 'Datastore retrieval batch size, defaults to 100') { |o| options[:batch] = Integer(o) }
end.parse!
if options[:env] == nil
db = SampleDocumentDatastore.new('db/sample_document_datastore.txt')
else
if ['PROD', 'DEV'].include? options[:env]
db = DocumentDatastore.new(options[:env])
else
raise OptionParser::InvalidArgument
end
end
begin
benchmark = Benchmark.measure {
Indexer.new(db, options[:batch]).start_indexing()
}
Log.benchmark("#{Time.now.to_i}\t#{options[:batch]}\t#{benchmark}")
Log::LOGGER.debug('Done!')
rescue Exception => e
Log::LOGGER.fatal(e.message)
Log::LOGGER.fatal(e.backtrace.inspect)
Log::LOGGER.debug('Failed!')
raise e
end