Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So that web archiving shelving jobs don't time out.
- Loading branch information
Showing
5 changed files
with
98 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# Move files to Stacks in the background | ||
class ShelveJob < ApplicationJob | ||
queue_as :default | ||
|
||
# @param [String] druid the identifier of the item to be published | ||
# @param [BackgroundJobResult] background_job_result identifier of a background job result to store status info | ||
def perform(druid:, background_job_result:) | ||
background_job_result.processing! | ||
|
||
begin | ||
item = Dor.find(druid) | ||
ShelvingService.shelve(item) | ||
rescue ShelvingService::ContentDirNotFoundError => e | ||
background_job_result.output = { errors: [{ title: 'Content directory not found', detail: e.message }] } | ||
background_job_result.complete! | ||
end | ||
|
||
background_job_result.complete! | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ShelveJob, type: :job do | ||
subject(:perform) { described_class.perform_now(druid: druid, background_job_result: result) } | ||
|
||
let(:druid) { 'druid:mk420bs7601' } | ||
let(:result) { create(:background_job_result) } | ||
let(:item) { instance_double(Dor::Item) } | ||
|
||
before do | ||
allow(Dor).to receive(:find).with(druid).and_return(item) | ||
allow(result).to receive(:processing!) | ||
end | ||
|
||
context 'with no errors' do | ||
before do | ||
allow(ShelvingService).to receive(:shelve) | ||
perform | ||
end | ||
|
||
it 'marks the job as processing' do | ||
expect(result).to have_received(:processing!).once | ||
end | ||
|
||
it 'invokes the ShelvingService' do | ||
expect(ShelvingService).to have_received(:shelve).with(item).once | ||
end | ||
|
||
it 'marks the job as complete' do | ||
expect(result).to be_complete | ||
end | ||
|
||
it 'has no output' do | ||
expect(result.output).to be_blank | ||
end | ||
end | ||
|
||
context 'with errors returned by ShelvingService' do | ||
let(:error_message) { "file isn't where we looked" } | ||
|
||
before do | ||
allow(ShelvingService).to receive(:shelve).and_raise(ShelvingService::ContentDirNotFoundError, error_message) | ||
end | ||
|
||
it 'marks the job as errored' do | ||
perform | ||
expect(result).to have_received(:processing!).once | ||
expect(ShelvingService).to have_received(:shelve).with(item).once | ||
expect(result).to be_complete | ||
expect(result.output[:errors]).to eq [{ 'detail' => error_message, 'title' => 'Content directory not found' }] | ||
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