Skip to content

Commit

Permalink
use posix-spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
lbiedinger committed Sep 1, 2015
1 parent 8de06d9 commit 28ce9fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion hydra-derivatives.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

21 changes: 10 additions & 11 deletions lib/hydra/derivatives/shell_based_processor.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand Down Expand Up @@ -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

0 comments on commit 28ce9fd

Please sign in to comment.