-
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.
Update Records from Plum automatically.
This subscribes to Plum's RabbitMQ exchange and uses the events there to keep Pomegranate up to date with Plum.
- Loading branch information
1 parent
17fdb2b
commit de68925
Showing
23 changed files
with
2,381 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,4 @@ gem 'social-share-button' | |
gem 'devise_invitable' | ||
gem 'iiif-presentation' | ||
gem 'omniauth-cas' | ||
gem 'sneakers' |
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 @@ | ||
class PlumEventProcessor | ||
attr_reader :event | ||
def initialize(event) | ||
@event = event | ||
end | ||
|
||
delegate :process, to: :processor | ||
|
||
private | ||
|
||
def event_type | ||
event["event"] | ||
end | ||
|
||
def processor | ||
case event_type | ||
when "CREATED" | ||
CreateProcessor.new(event) | ||
when "UPDATED" | ||
UpdateProcessor.new(event) | ||
when "DELETED" | ||
DeleteProcessor.new(event) | ||
else | ||
UnknownEvent.new(event) | ||
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,10 @@ | ||
class PlumEventProcessor | ||
class CreateProcessor < Processor | ||
def process | ||
exhibits.map do |exhibit| | ||
resource = IIIFResource.new(manifest_url: manifest_url, exhibit: exhibit) | ||
resource.save_and_index | ||
end.all?(&:present?) | ||
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,12 @@ | ||
class PlumEventProcessor | ||
class DeleteProcessor < Processor | ||
def process | ||
IIIFResource.where(url: manifest_url).each do |resource| | ||
index.delete_by_id resource.id.to_s | ||
index.commit | ||
resource.destroy | ||
end | ||
true | ||
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,30 @@ | ||
class PlumEventProcessor | ||
class Processor | ||
attr_reader :event | ||
def initialize(event) | ||
@event = event | ||
end | ||
|
||
private | ||
|
||
def exhibits | ||
Spotlight::Exhibit.where("slug IN (?)", collection_slugs) | ||
end | ||
|
||
def manifest_url | ||
event["manifest_url"] | ||
end | ||
|
||
def collection_slugs | ||
event["collection_slugs"] | ||
end | ||
|
||
def event_type | ||
event["event"] | ||
end | ||
|
||
def index | ||
Blacklight.default_index.connection | ||
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,13 @@ | ||
class PlumEventProcessor | ||
class UnknownEvent < Processor | ||
attr_reader :event | ||
def initialize(event) | ||
@event = event | ||
end | ||
|
||
def process | ||
Rails.logger.info("Unable to process event type #{event_type}") | ||
false | ||
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,54 @@ | ||
class PlumEventProcessor | ||
class UpdateProcessor < Processor | ||
def process | ||
delete_old_resources | ||
update_existing_resources | ||
create_new_resources | ||
true | ||
end | ||
|
||
def delete_old_resources | ||
delete_resources.each do |resource| | ||
index.delete_by_id resource.id.to_s | ||
index.commit | ||
resource.destroy | ||
end | ||
end | ||
|
||
def update_existing_resources | ||
IIIFResource.where(url: manifest_url).each(&:save_and_index) | ||
end | ||
|
||
def create_new_resources | ||
new_exhibits.each do |exhibit| | ||
IIIFResource.new(manifest_url: manifest_url, exhibit: exhibit).save_and_index | ||
end | ||
end | ||
|
||
private | ||
|
||
def new_exhibits | ||
Spotlight::Exhibit.where("slug IN (?)", new_exhibit_slugs) | ||
end | ||
|
||
def new_exhibit_slugs | ||
collection_slugs - existing_slugs | ||
end | ||
|
||
def delete_resources | ||
IIIFResource.where(url: manifest_url).joins(:exhibit).where('spotlight_exhibits.slug IN (?)', delete_slugs) | ||
end | ||
|
||
def delete_slugs | ||
existing_slugs - collection_slugs | ||
end | ||
|
||
def existing_slugs | ||
existing_resources.map(&:exhibit).map(&:slug) | ||
end | ||
|
||
def existing_resources | ||
IIIFResource.where(url: manifest_url) | ||
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,14 @@ | ||
class PlumEventHandler | ||
include Sneakers::Worker | ||
from_queue :pomegranate | ||
|
||
def work(msg) | ||
msg = JSON.parse(msg) | ||
result = PlumEventProcessor.new(msg).process | ||
if result | ||
ack! | ||
else | ||
reject! | ||
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env sh | ||
|
||
until $(curl --output /dev/null --silent --head --fail http://localhost:8983/solr); do | ||
until $(curl --output /dev/null --silent --head --fail http://localhost:8980/solr); do | ||
printf '.' | ||
sleep 1 | ||
done |
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,8 @@ | ||
require 'sneakers' | ||
require_relative 'pom_config' | ||
Sneakers.configure( | ||
amqp: Pomegranate.config["events"]["server"], | ||
exchange: Pomegranate.config["events"]["exchange"], | ||
exchange_type: :fanout | ||
) | ||
Sneakers.logger.level = Logger::INFO |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.