Skip to content

Commit

Permalink
Work on logging index events
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Jan 10, 2019
1 parent 00e5d86 commit 9d65c27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 9 additions & 1 deletion app/jobs/iiif_ingest_job.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
class IIIFIngestJob < ActiveJob::Base
# Ingest one or more IIIF manfiest URLs. Each manifest is ingested as its
# own resource.
def perform(urls, exhibit)
def perform(urls, exhibit, log_entry)
Array.wrap(urls).each do |url|
ingest url, exhibit
end

# Lock the row to prevent multiple workers from overwriting each other's increments.
# This worked, but it's reporting complete before the objects are reindexed.
# app/models/spotlight/resource.rb:55 has a null reindexing_log_entry.
log_entry.with_lock do
previous = log_entry.items_reindexed_count || 0
log_entry.update(items_reindexed_count: previous + Array.wrap(urls).size)
end
end

# Ingest a single IIIF manifest URL as a resource.
Expand Down
4 changes: 2 additions & 2 deletions app/models/exhibit_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ def initialize(exhibit)
@exhibit = exhibit
end

def reindex(*_args)
def reindex(log_entry)
members.each_slice(50) do |slice|
IIIFIngestJob.perform_later slice, exhibit
IIIFIngestJob.perform_later slice, exhibit, log_entry
end
end

Expand Down
12 changes: 10 additions & 2 deletions spec/jobs/iiif_ingest_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe IIIFIngestJob do
let(:url1) { 'http://example.com/1/manifest' }
let(:url2) { 'http://example.com/2/manifest' }
let(:log_entry) { Spotlight::ReindexingLogEntry.new }
let(:exhibit) { Spotlight::Exhibit.new }
let(:resource) { IIIFResource.new url: nil, exhibit: exhibit }

Expand All @@ -14,13 +15,20 @@
it 'ingests a single url' do
expect(IIIFResource).to receive(:new).with(url: url1, exhibit_id: exhibit.id).and_return(resource)

described_class.new.perform(url1, exhibit)
described_class.new.perform(url1, exhibit, log_entry)
end

it 'ingests each of an array of urls' do
expect(IIIFResource).to receive(:new).with(url: url1, exhibit_id: exhibit.id).and_return(resource)
expect(IIIFResource).to receive(:new).with(url: url2, exhibit_id: exhibit.id).and_return(resource)

described_class.new.perform([url1, url2], exhibit)
described_class.new.perform([url1, url2], exhibit, log_entry)
end

describe 'incrementing the log entry' do
it 'increments the exhibit log entry' do
described_class.new.perform([url1, url2], exhibit, log_entry)
expect(log_entry.items_reindexed_count).to eq 2
end
end
end

0 comments on commit 9d65c27

Please sign in to comment.