Class: RealtimeIndexer

Inherits:
IndexerCommon show all
Defined in:
indexer/app/lib/realtime_indexer.rb

Constant Summary

Constants inherited from IndexerCommon

IndexerCommon::EXCLUDED_STRING_VALUE_PROPERTIES

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

Instance Method Summary collapse

Methods inherited from IndexerCommon

#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, #t, #trim_ark_value

Methods included from JSONModel

JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository

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

#runObject



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
    

    # Blocks until something turns up
    updates = get_updates(last_sequence)

    if !updates.empty?

      # Pick out updates that represent deleted records
      deletes = updates.find_all { |update| update['record'] == 'deleted' }

      # Add the records that were created/updated
      index_records(updates - deletes)

      # Delete records that were deleted
      delete_records(deletes.map { |record| record['uri'] })

      send_commit(:soft)
      next_sequence = updates.last['sequence']
    end
  rescue Timeout::Error
    # Doesn't matter...
  rescue
    reset_session
    Log.error("#{$!.inspect}")
    Log.error($@.join("\n"))
    sleep 5
  end

  next_sequence
end