-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reindex locally instead of sending object update message.
closes #4885
- Loading branch information
1 parent
bfc1f3f
commit fcf3e52
Showing
12 changed files
with
94 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# Reindexes an object. | ||
class ReindexJob < ApplicationJob | ||
queue_as :default | ||
|
||
# @param [Hash] model the cocina object attributes (without metadata) | ||
# @param [DateTime] created the time the object was created | ||
# @param [DateTime] modified the time the object was last modified | ||
def perform(model:, created:, modified:) | ||
cocina_object = Cocina::Models.build(model) | ||
cocina_object_with_metadata = Cocina::Models.with_metadata(cocina_object, 'void', created:, modified:) | ||
Indexer.reindex(cocina_object: cocina_object_with_metadata) | ||
rescue DorIndexing::RepositoryError => e | ||
Rails.logger.error("Error reindexing #{model[:externalIdentifier]}: #{e.message}") | ||
Honeybadger.notify(e, context: { druid: model[:externalIdentifier] }) | ||
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 was deleted.
Oops, something went wrong.
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ReindexJob do | ||
subject(:perform) do | ||
described_class.perform_now(model: dro.to_h, created: Time.zone.now, modified: Time.zone.now) | ||
end | ||
|
||
let(:dro) { build(:dro) } | ||
|
||
context 'when no errors' do | ||
before do | ||
allow(Indexer).to receive(:reindex) | ||
end | ||
|
||
it 'invokes the Indexer' do | ||
perform | ||
expect(Indexer).to have_received(:reindex).with(cocina_object: an_instance_of(Cocina::Models::DROWithMetadata)) | ||
end | ||
end | ||
|
||
context 'when an error' do | ||
before do | ||
allow(Indexer).to receive(:reindex).and_raise(DorIndexing::RepositoryError) | ||
allow(Honeybadger).to receive(:notify) | ||
end | ||
|
||
it 'Honeybadger alerts' do | ||
perform | ||
expect(Indexer).to have_received(:reindex).with(cocina_object: an_instance_of(Cocina::Models::DROWithMetadata)) | ||
expect(Honeybadger).to have_received(:notify) | ||
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
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 was deleted.
Oops, something went wrong.
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