From a37b34d7c54217f9a77f1299afbd9e96da4b0e66 Mon Sep 17 00:00:00 2001 From: val99erie Date: Thu, 6 Apr 2017 11:07:35 -0500 Subject: [PATCH 1/2] Handle the case where active_encode returns a 'cancelled' status. Part of story avalonmediasystem/avalon#1785 --- .../derivatives/processors/active_encode.rb | 15 ++++++---- spec/processors/active_encode_spec.rb | 29 ++++++++++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/hydra/derivatives/processors/active_encode.rb b/lib/hydra/derivatives/processors/active_encode.rb index b80fa32..6b3ea39 100644 --- a/lib/hydra/derivatives/processors/active_encode.rb +++ b/lib/hydra/derivatives/processors/active_encode.rb @@ -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 diff --git a/spec/processors/active_encode_spec.rb b/spec/processors/active_encode_spec.rb index 86b0cde..8738cdb 100644 --- a/spec/processors/active_encode_spec.rb +++ b/spec/processors/active_encode_spec.rb @@ -11,16 +11,24 @@ 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 @@ -28,5 +36,18 @@ 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 From a2badd64788f285ae78c4bd66128b0808f82f868 Mon Sep 17 00:00:00 2001 From: val99erie Date: Tue, 11 Apr 2017 09:30:09 -0500 Subject: [PATCH 2/2] rubocop --- .rubocop.yml | 4 ++++ lib/hydra/derivatives/services/uri_source_file_service.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 83b0ce9..eefd87d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -43,6 +43,10 @@ Style/PredicateName: Style/RaiseArgs: Enabled: false +Style/HashSyntax: + Exclude: + - spec/processors/active_encode_spec.rb + RSpec/ExampleWording: CustomTransform: be: is diff --git a/lib/hydra/derivatives/services/uri_source_file_service.rb b/lib/hydra/derivatives/services/uri_source_file_service.rb index 54a128d..99d706d 100644 --- a/lib/hydra/derivatives/services/uri_source_file_service.rb +++ b/lib/hydra/derivatives/services/uri_source_file_service.rb @@ -5,7 +5,7 @@ class UriSourceFileService # @param [Hash] options # @option options [Symbol] :source a method that can be called on the object to retrieve the source file # @yield [Tempfile] a temporary source file that has a lifetime of the block - def self.call(object, options, &block) + def self.call(object, options, &_block) source_name = options.fetch(:source) yield(object.send(source_name).uri.to_s) end