Skip to content

Commit

Permalink
Show an error to the users if their job fails
Browse files Browse the repository at this point in the history
Presently, it just raises an error and the user never sees their job complete.
Fixes #560
  • Loading branch information
jcoyne committed Dec 18, 2019
1 parent 89cdd47 commit d75c2c6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
8 changes: 4 additions & 4 deletions app/lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ def process_digital_objects
begin
# Try to pre_assemble the digital object.
load_checksums(dobj)
dobj.pre_assemble
status = dobj.pre_assemble
# Indicate that we finished.
dobj.pre_assem_finished = true
log "Completed #{dobj.druid}"
ensure
# Log the outcome no matter what.
File.open(progress_log_file, 'a') { |f| f.puts log_progress_info(dobj).to_yaml }
File.open(progress_log_file, 'a') { |f| f.puts log_progress_info(dobj, status).to_yaml }
end
end
ensure
Expand All @@ -137,13 +137,13 @@ def objects_to_process
@o2p ||= digital_objects.reject { |dobj| skippables.key?(dobj.container) }
end

def log_progress_info(dobj)
def log_progress_info(dobj, status)
{
container: dobj.container,
pid: dobj.pid,
pre_assem_finished: dobj.pre_assem_finished,
timestamp: Time.now.strftime('%Y-%m-%d %H:%I:%S')
}
}.merge(status)
end

private
Expand Down
4 changes: 3 additions & 1 deletion app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ def content_md_creation_style
# The main process.
####

# @return [Hash] the status of the attempt and an optional message
def pre_assemble
log " - pre_assemble(#{source_id}) started"
raise "#{druid.druid} can't be opened for a new version; cannot re-accession when version > 1 unless object can be opened" if !openable? && current_object_version > 1
return { status: 'error', message: "can't be opened for a new version; cannot re-accession when version > 1 unless object can be opened" } if !openable? && current_object_version > 1
@assembly_directory = AssemblyDirectory.create(druid_id: druid.id)
stage_files
generate_content_metadata
generate_media_project_technical_metadata if content_md_creation == 'media_cm_style'
create_new_version if openable?
initialize_assembly_workflow
log " - pre_assemble(#{pid}) finished"
{ status: 'success' }
end

attr_reader :assembly_directory
Expand Down
34 changes: 22 additions & 12 deletions spec/lib/pre_assembly/bundle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@
expect { b.process_digital_objects }.not_to raise_error
end

it 'throws an exception for re-accessioned objects that are not ready to be versioned' do
allow_any_instance_of(PreAssembly::DigitalObject).to receive(:'openable?').and_return(false)
allow_any_instance_of(PreAssembly::DigitalObject).to receive(:current_object_version).and_return(2)
exp_msg = "druid:aa111aa1111 can't be opened for a new version; cannot re-accession when version > 1 unless object can be opened"
expect { b.process_digital_objects }.to raise_error(RuntimeError, exp_msg)
context 'when there are re-accessioned objects that are not ready to be versioned' do
before do
allow_any_instance_of(PreAssembly::DigitalObject).to receive(:'openable?').and_return(false)
allow_any_instance_of(PreAssembly::DigitalObject).to receive(:current_object_version).and_return(2)
end

it 'logs an error' do
b.process_digital_objects
yaml = YAML.load_file(b.progress_log_file)
expect(yaml[:status]).to eq 'error'
expect(yaml[:message]).to eq "can't be opened for a new version; cannot re-accession when version > 1 unless object can be opened"
end
end
end

Expand Down Expand Up @@ -137,16 +144,19 @@
end

describe '#log_progress_info' do
it 'returns expected info about a digital object' do
dobj = flat_dir_images.digital_objects[0]
exp = {
subject { flat_dir_images.log_progress_info(dobj, status: 'success') }

let(:dobj) { flat_dir_images.digital_objects[0] }

it {
is_expected.to eq(
container: dobj.container,
pid: dobj.pid,
pre_assem_finished: dobj.pre_assem_finished,
timestamp: Time.now.strftime('%Y-%m-%d %H:%I:%S')
}
expect(flat_dir_images.log_progress_info(dobj)).to eq(exp)
end
timestamp: Time.now.strftime('%Y-%m-%d %H:%I:%S'),
status: 'success'
)
}
end

### Private methods
Expand Down
19 changes: 13 additions & 6 deletions spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ def add_object_files(extension = 'tif')
object.pre_assemble
end

it 'throws an exception for existing non-openable objects' do
allow(object).to receive(:'openable?').and_return(false)
allow(object).to receive(:current_object_version).and_return(2)
expect(object).not_to receive(:stage_files)
exp_msg = "#{pid} can't be opened for a new version; cannot re-accession when version > 1 unless object can be opened"
expect { object.pre_assemble }.to raise_error(RuntimeError, exp_msg)
context 'when the object is not openable' do
before do
allow(object).to receive(:'openable?').and_return(false)
allow(object).to receive(:current_object_version).and_return(2)
end

let(:status) { object.pre_assemble }

it 'logs an error for existing non-openable objects' do
expect(object).not_to receive(:stage_files)
expect(status).to eq(status: 'error',
message: "can't be opened for a new version; cannot re-accession when version > 1 unless object can be opened")
end
end

it 'calls create_new_version for existing openable objects' do
Expand Down

0 comments on commit d75c2c6

Please sign in to comment.