Skip to content

Commit

Permalink
Merge pull request #153 from projecthydra/config_poll_time
Browse files Browse the repository at this point in the history
Configure the poll time for ActiveEncode. Part of story avalonmediasystem/avalon#1785
  • Loading branch information
cjcolvar committed Apr 18, 2017
2 parents 0b2e5f3 + e238309 commit 727fd73
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -88,6 +88,13 @@ Hydra::Derivatives::Processors::Video::Processor.config.mkv.codec = '-vcodec ffv
Hydra::Derivatives::Processors::Video::Processor.config.jpeg.codec = '-vcodec mjpeg'
```

### Configuration for Audio/Video Processing with ActiveEncode

```ruby
# Sleep time (in seconds) to poll for status of encoding job
Hydra::Derivatives.active_encode_poll_time = 10
```

### Additional Directives

#### Layers
Expand Down
2 changes: 1 addition & 1 deletion lib/hydra/derivatives.rb
Expand Up @@ -53,7 +53,7 @@ def self.reset_config!
end

CONFIG_METHODS = [:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :kdu_compress_path,
:kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service].freeze
:kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service, :active_encode_poll_time].freeze
CONFIG_METHODS.each do |method|
module_eval <<-RUBY
def self.#{method}
Expand Down
10 changes: 9 additions & 1 deletion lib/hydra/derivatives/config.rb
Expand Up @@ -5,7 +5,8 @@ module Derivatives
class Config
attr_writer :ffmpeg_path, :libreoffice_path, :temp_file_base,
:source_file_service, :output_file_service, :fits_path,
:enable_ffmpeg, :kdu_compress_path, :kdu_compress_recipes
:enable_ffmpeg, :kdu_compress_path, :kdu_compress_recipes,
:active_encode_poll_time

def ffmpeg_path
@ffmpeg_path ||= 'ffmpeg'
Expand Down Expand Up @@ -72,6 +73,13 @@ def kdu_compress_recipes
"Stiles={1024,1024}" ).gsub(/\s+/, " ").strip
}
end

# The poll time (in seconds) that the active encode
# processor will sleep before it checks the status of an
# encoding job.
def active_encode_poll_time
@active_encode_poll_time ||= 10
end
end
end
end
4 changes: 1 addition & 3 deletions lib/hydra/derivatives/processors/active_encode.rb
Expand Up @@ -16,10 +16,8 @@ def process
# override it with a sub-class of AE::Base.
encode = ::ActiveEncode::Base.create(source_path, directives)

# TODO: Instead of hard-coding sleep time, make a config

# Wait until the encoding job is finished
sleep 10 while encode.reload.running?
sleep Hydra::Derivatives.active_encode_poll_time while encode.reload.running?

# TODO: Handle timeout
# https://github.com/projecthydra/hydra-derivatives#processing-timeouts
Expand Down
6 changes: 6 additions & 0 deletions spec/units/config_spec.rb
Expand Up @@ -41,4 +41,10 @@
subject.source_file_service = source_file_service
expect(subject.source_file_service).to eq(source_file_service)
end

it "lets you set the poll time for ActiveEncode jobs" do
expect(subject.active_encode_poll_time).to eq 10
subject.active_encode_poll_time = 15
expect(subject.active_encode_poll_time).to eq 15
end
end
4 changes: 4 additions & 0 deletions spec/units/derivatives_spec.rb
Expand Up @@ -53,6 +53,10 @@ class CustomFile < ActiveFedora::Base
subject.kdu_compress_path = '/usr/local/bin/kdu_compress'
subject.reset_config!
expect(subject.kdu_compress_path).to eq('kdu_compress')

subject.active_encode_poll_time = 2
subject.reset_config!
expect(subject.active_encode_poll_time).to eq 10
end
end
end

0 comments on commit 727fd73

Please sign in to comment.