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

Handle the case where active_encode returns a 'cancelled' status #150

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions lib/hydra/derivatives/processors/active_encode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ module Hydra::Derivatives::Processors
class ActiveEncode < Processor
def process
encode = ::ActiveEncode::Base.create(source_path, directives)

# TODO: wait until the encode job succeeds then call output_file_service with the output url
# while(encode.reload.running?) do
# p "Wait: #{Time.now}"
# sleep 10
# end
# while(encode.reload.running?) { sleep 10 }

raise_exception_if_encoding_failed(encode)
raise_exception_if_encoding_cancelled(encode)

# 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
29 changes: 25 additions & 4 deletions spec/processors/active_encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,43 @@
describe '#process' do
subject { processor.process }

let(:encode_double) { double('encode double', reload: self, state: state, errors: errors) }
# Mock out the actual encoding, just pretend that the
# encode finished and returned a certain status.
let(:failed_status) { false }
let(:cancelled_status) { false }
let(:errors) { [] }
let(:encode_double) do
double('encode double',
reload: self, state: state, errors: errors,
:failed? => failed_status,
:cancelled? => cancelled_status)
end

context 'when the encoding failed' do
let(:state) { :failed }
let(:failed_status) { true }
let(:errors) { ['error 1', 'error 2'] }

# Mock out the actual encoding, just pretend that the
# encode returned a failed status.
before do
allow(encode_double).to receive(:failed?).and_return(true)
allow(::ActiveEncode::Base).to receive(:create).and_return(encode_double)
end

it 'raises an exception' do
expect { subject }.to raise_error('Encoding failed: error 1 ; error 2')
end
end

context 'when the encoding was cancelled' do
let(:state) { :cancelled }
let(:cancelled_status) { true }

before do
allow(::ActiveEncode::Base).to receive(:create).and_return(encode_double)
end

it 'raises an exception' do
expect { subject }.to raise_error("Encoding cancelled: #{file_path}")
end
end
end
end