Class: RealtimeIndexer
Instance Method Summary
collapse
#add_agents, #add_arks, add_attribute_to_resolve, #add_audit_info, #add_batch_hook, #add_delete_hook, #add_document_prepare_hook, #add_extents, #add_extra_documents_hook, add_indexer_initialize_hook, #add_level, #add_notes, #add_subjects, #add_subjects_subrecord, #add_summary, #add_years, #apply_pui_fields, #build_fullrecord, #clean_for_sort, #clean_whitespace, #configure_doc_rules, #dedupe_by_uri, #delete_records, #do_http_request, #enum_fields, extract_string_values, generate_permutations_for_identifier, generate_sort_string_for_identifier, generate_years_for_date_range, #get_record_scope, #index_batch, #index_records, #is_repository_unpublished?, #login, pause, paused?, #paused?, #record_has_children, #record_types, #records_with_children, #reset_session, #resolved_attributes, #sanitize_json, #send_commit, #skip_index_doc?, #skip_index_record?, #solr_url, #trim_ark_value
Constructor Details
#initialize(backend_url, should_continue) ⇒ RealtimeIndexer
Returns a new instance of RealtimeIndexer.
6
7
8
9
10
11
|
# File 'indexer/app/lib/realtime_indexer.rb', line 6
def initialize(backend_url, should_continue)
super(backend_url)
@backend_url = backend_url
@should_continue = should_continue
end
|
Instance Method Details
#get_updates(last_sequence = 0) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'indexer/app/lib/realtime_indexer.rb', line 13
def get_updates(last_sequence = 0)
resolve_params = resolved_attributes.map {|a| "resolve[]=#{a}"}.join("&")
response = do_http_request(URI.parse(@backend_url),
Net::HTTP::Get.new("/update-feed?last_sequence=#{last_sequence}&#{resolve_params}"))
if response.code != '200'
raise "Indexing error: #{response.body}"
end
ASUtils.json_parse(response.body)
end
|
#run ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'indexer/app/lib/realtime_indexer.rb', line 62
def run
last_sequence = 0
while @should_continue.call
last_sequence = run_index_round(last_sequence) unless paused?
end
end
|
#run_index_round(last_sequence) ⇒ Object
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
|
# File 'indexer/app/lib/realtime_indexer.rb', line 28
def run_index_round(last_sequence)
next_sequence = last_sequence
begin
login
updates = get_updates(last_sequence)
if !updates.empty?
deletes = updates.find_all { |update| update['record'] == 'deleted' }
index_records(updates - deletes)
delete_records(deletes.map { |record| record['uri'] })
send_commit(:soft)
next_sequence = updates.last['sequence']
end
rescue Timeout::Error
rescue
reset_session
Log.error("#{$!.inspect}")
Log.error($@.join("\n"))
sleep 5
end
next_sequence
end
|