Skip to content

Commit

Permalink
Handling errors encountered during the reindexing process for IIIFRes…
Browse files Browse the repository at this point in the history
…ources
  • Loading branch information
jrgriffiniii committed Feb 21, 2019
1 parent b42a5f5 commit 1aebe94
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,6 @@ RSpec/AnyInstance:
Exclude:
- 'spec/support/stub_iiif_response.rb'
- 'spec/features/catalog_show_spec.rb'
RSpec/NestedGroups:
Exclude:
- 'spec/models/iiif_resource_spec.rb'
3 changes: 3 additions & 0 deletions app/models/iiif_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def write_to_index(batch)

blacklight_solr.update data: documents.to_json,
headers: { 'Content-Type' => 'application/json' }
rescue RSolr::Error::Http => rsolr_error
Rails.logger.error "Failed to update Solr for the following documents: #{document_ids.join(', ')}"
raise rsolr_error
end

# Override hard commit after indexing every document, for performance.
Expand Down
45 changes: 45 additions & 0 deletions spec/models/iiif_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,50 @@
expect(Spotlight::ReindexJob).to have_received(:perform_now)
end
end

describe '#reindex' do
let(:exhibit) { Spotlight::Exhibit.create title: 'Exhibit A' }
let(:resource) { described_class.new url: url, exhibit: exhibit }
let(:blacklight_solr) { instance_double(RSolr::Client) }
let(:data) { resource.document_builder.documents_to_index.to_a }

before do
stub_manifest(
url: url,
fixture: "vol1.json"
)
allow(blacklight_solr).to receive(:update)
allow(resource).to receive(:blacklight_solr).and_return(blacklight_solr)
resource.reindex
end

# JSON-serialization does not preserve the order of properties, so this
# cannot be tested
it 'reindexes by directly updating Solr' do
expect(blacklight_solr).to have_received(:update).with(
hash_including(headers: { 'Content-Type' => 'application/json' })
)
end

context 'when a Solr error is encountered' do
let(:request) { double }
let(:response) { double }
let(:rsolr_error) { RSolr::Error::Http.new(request, response) }
let(:ids) do
docs = resource.document_builder.documents_to_index
docs.map { |document| document[:id] }
end

before do
allow(Rails.logger).to receive(:error)
allow(blacklight_solr).to receive(:update).and_raise(rsolr_error)
end

it 'logs an error' do
expect { resource.reindex }.to raise_error(rsolr_error)
expect(Rails.logger).to have_received(:error).with("Failed to update Solr for the following documents: #{ids.join(', ')}")
end
end
end
end
end

0 comments on commit 1aebe94

Please sign in to comment.