diff --git a/hydra-derivatives.gemspec b/hydra-derivatives.gemspec index 38d9fc1..bacde4a 100644 --- a/hydra-derivatives.gemspec +++ b/hydra-derivatives.gemspec @@ -4,7 +4,7 @@ version = File.read(File.expand_path("../VERSION", __FILE__)).strip Gem::Specification.new do |spec| spec.name = "hydra-derivatives" - spec.version = version + spec.version = version spec.authors = ["Justin Coyne"] spec.email = ["justin@curationexperts.com"] spec.description = %q{Derivative generation plugin for hydra} @@ -25,6 +25,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'active-fedora' spec.add_dependency 'hydra-file_characterization' spec.add_dependency 'mini_magick' + spec.add_dependency 'posix-spawn' spec.add_dependency 'activesupport', '>= 3.2.13', '< 5.0' end diff --git a/lib/hydra/derivatives/shell_based_processor.rb b/lib/hydra/derivatives/shell_based_processor.rb index 5ae3482..d4c188b 100644 --- a/lib/hydra/derivatives/shell_based_processor.rb +++ b/lib/hydra/derivatives/shell_based_processor.rb @@ -1,16 +1,13 @@ # An abstract class for asyncronous jobs that transcode files using FFMpeg require 'tmpdir' -require 'open3' +require 'posix-spawn' module Hydra module Derivatives module ShellBasedProcessor extend ActiveSupport::Concern - included do - extend Open3 - end def process directives.each do |name, args| @@ -39,15 +36,17 @@ def encode_datastream(dest_dsid, file_suffix, mime_type, options = '') module ClassMethods def execute(command) - stdin, stdout, stderr, wait_thr = popen3(command) - stdin.close - out = stdout.read - stdout.close - err = stderr.read - stderr.close - raise "Unable to execute command \"#{command}\"\n#{err}" unless wait_thr.value.success? + stdout, stderr, status = execute_posix_spawn(*command) + raise "Unable to execute command \"#{command}\"\n#{stderr}" unless status.exitstatus.success? end end + + def execute_posix_spawn(*command) + pid, stdin, stdout, stderr = POSIX::Spawn.popen4(*command) + Process.waitpid(pid) + + [stdout.read, stderr.read, $?] + end end end end