Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filename to error message #151

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions lib/hydra/derivatives/processors/active_encode.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
require 'active_encode'

module Hydra::Derivatives::Processors
class ActiveEncodeError < StandardError
def initialize(status, source_path, errors = [])
msg = "ActiveEncode status was \"#{status}\" for #{source_path}"
msg = "#{msg}: #{errors.join(' ; ')}" unless errors.empty?
super(msg)
end
end

class ActiveEncode < Processor
def process
encode = ::ActiveEncode::Base.create(source_path, directives)

# Wait until the encoding job is finished
# while(encode.reload.running?) { sleep 10 }

raise_exception_if_encoding_failed(encode)
raise_exception_if_encoding_cancelled(encode)
raise ActiveEncodeError.new(encode.state, source_path, encode.errors) unless encode.completed?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always throw an error since we're not blocking until the job is finished yet? Seems like it will always have a status of :running when it gets to this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, that encoding on line 14 can never work. That isn't the correct method signature, is it? I have code on my other branch that creates the encode differently and waits for it to finish running.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is okay, but maybe we can just forget about that point right now. Assuming the encode job is blocking then I think the unless completed check is correct.


# TODO: call output_file_service with the output url
end

def raise_exception_if_encoding_failed(encode)
return unless encode.failed?
raise StandardError.new("Encoding failed: #{encode.errors.join(' ; ')}")
end

def raise_exception_if_encoding_cancelled(encode)
return unless encode.cancelled?
raise StandardError.new("Encoding cancelled: #{source_path}")
end
end
end
6 changes: 4 additions & 2 deletions spec/processors/active_encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# encode finished and returned a certain status.
let(:failed_status) { false }
let(:cancelled_status) { false }
let(:completed_status) { false }
let(:errors) { [] }
let(:encode_double) do
double('encode double',
reload: self, state: state, errors: errors,
:completed? => completed_status,
:failed? => failed_status,
:cancelled? => cancelled_status)
end
Expand All @@ -33,7 +35,7 @@
end

it 'raises an exception' do
expect { subject }.to raise_error('Encoding failed: error 1 ; error 2')
expect { subject }.to raise_error(Hydra::Derivatives::Processors::ActiveEncodeError, "ActiveEncode status was \"failed\" for #{file_path}: error 1 ; error 2")
end
end

Expand All @@ -46,7 +48,7 @@
end

it 'raises an exception' do
expect { subject }.to raise_error("Encoding cancelled: #{file_path}")
expect { subject }.to raise_error(Hydra::Derivatives::Processors::ActiveEncodeError, "ActiveEncode status was \"cancelled\" for #{file_path}")
end
end
end
Expand Down