-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reindex the entire collection when you hit 'reindex
- Loading branch information
1 parent
ff769b4
commit 8194d37
Showing
13 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Spotlight | ||
## | ||
# Reindex the given resources or exhibits | ||
class ReindexJob < ActiveJob::Base | ||
queue_as :default | ||
|
||
before_enqueue do |job| | ||
resource_list(job.arguments.first).each(&:waiting!) | ||
end | ||
|
||
def perform(exhibit_or_resources) | ||
resource_list(exhibit_or_resources).each(&:reindex) | ||
end | ||
|
||
private | ||
|
||
def resource_list(exhibit_or_resources) | ||
if exhibit_or_resources.is_a?(Spotlight::Exhibit) | ||
[ExhibitProxy.new(exhibit_or_resources)] | ||
elsif exhibit_or_resources.is_a?(Enumerable) | ||
exhibit_or_resources | ||
else | ||
Array(exhibit_or_resources) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class ExhibitProxy | ||
attr_reader :exhibit | ||
def initialize(exhibit) | ||
@exhibit = exhibit | ||
end | ||
|
||
def reindex | ||
IIIFIngestJob.perform_now members, exhibit | ||
end | ||
|
||
def collection_manifest | ||
CollectionManifest.find_by_slug(exhibit.slug) | ||
end | ||
|
||
def members | ||
collection_manifest.manifests.map { |x| x['@id'] } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
class IIIFResource < Spotlight::Resources::IiifHarvester | ||
belongs_to :exhibit, class_name: 'Spotlight::Exhibit' | ||
|
||
def initialize(manifest_url: nil, exhibit: nil) | ||
super() | ||
self.url = manifest_url | ||
self.exhibit_id = exhibit.id if exhibit | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Spotlight::ReindexJob do | ||
let(:url1) { 'http://example.com/1/manifest' } | ||
let(:exhibit) { Spotlight::Exhibit.new } | ||
let(:resource) { IIIFResource.new url: nil, exhibit: exhibit } | ||
let(:manifest) { object_double(CollectionManifest.new, manifests: [{ "@id" => url1 }]) } | ||
|
||
before do | ||
allow(exhibit).to receive(:id).and_return('exhibit1') | ||
allow(CollectionManifest).to receive(:find_by_slug).and_return(manifest) | ||
allow(resource).to receive(:save_and_index) | ||
end | ||
|
||
it 'reindexes an exhibit' do | ||
allow(IIIFResource).to receive(:new).and_return(resource) | ||
|
||
described_class.perform_now(exhibit) | ||
|
||
expect(IIIFResource).to have_received(:new).with(url: url1, exhibit_id: exhibit.id) | ||
end | ||
|
||
it 'can reindex multiple IIIF Resources' do | ||
resources = [instance_double(IIIFResource, reindex: true), instance_double(IIIFResource, reindex: true)] | ||
|
||
described_class.perform_now(resources) | ||
|
||
expect(resources.first).to have_received(:reindex) | ||
expect(resources.last).to have_received(:reindex) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters