class Hydra::Derivatives::Processors::ActiveEncode

Attributes

encode_class[RW]
encode_job[R]

Public Class Methods

new(source_path, directives, opts = {}) click to toggle source
Calls superclass method
# File lib/hydra/derivatives/processors/active_encode.rb, line 17
def initialize(source_path, directives, opts = {})
  super
  @encode_class = opts.delete(:encode_class) || ::ActiveEncode::Base
end

Public Instance Methods

process() click to toggle source
# File lib/hydra/derivatives/processors/active_encode.rb, line 22
def process
  @encode_job = encode_class.create(source_path, directives)
  timeout ? wait_for_encode_job_with_timeout : wait_for_encode_job
  encode_job.output.each do |output|
    output_file_service.call(output, directives)
  end
end

Private Instance Methods

cleanup_after_timeout() click to toggle source

After a timeout error, try to cancel the encoding.

# File lib/hydra/derivatives/processors/active_encode.rb, line 46
def cleanup_after_timeout
  encode_job.cancel!
rescue StandardError => e
  cancel_error = e
ensure
  msg = "Unable to process ActiveEncode derivative: The command took longer than #{timeout} seconds to execute. Encoding will be cancelled."
  msg = "#{msg} An error occurred while trying to cancel encoding: #{cancel_error}" if cancel_error
  raise Hydra::Derivatives::TimeoutError, msg
end
wait_for_encode_job() click to toggle source

Wait until the encoding job is finished. If the status is anything other than 'completed', raise an error.

# File lib/hydra/derivatives/processors/active_encode.rb, line 40
def wait_for_encode_job
  sleep Hydra::Derivatives.active_encode_poll_time while encode_job.reload.running?
  raise ActiveEncodeError.new(encode_job.state, source_path, encode_job.errors) unless encode_job.completed?
end
wait_for_encode_job_with_timeout() click to toggle source
# File lib/hydra/derivatives/processors/active_encode.rb, line 32
def wait_for_encode_job_with_timeout
  Timeout.timeout(timeout) { wait_for_encode_job }
rescue Timeout::Error
  cleanup_after_timeout
end