Skip to content

Commit

Permalink
Adding a timeout to the derivative executable running so soffice does…
Browse files Browse the repository at this point in the history
… not hang. fixes #9607
  • Loading branch information
carolyncole committed Sep 24, 2014
1 parent 78c8bc0 commit ea86cea
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion config/initializers/video_processor_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,27 @@ def codecs(format)
end
end

end
end
Hydra::Derivatives::ShellBasedProcessor::ClassMethods.class_eval do
alias_method :old_execute, :execute
def execute(command)
puts "got to override"
timeout = 5*60 # 5 minutes
wait_thr = nil
begin
status = Timeout::timeout(timeout) do
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?
end
rescue Timeout::Error => ex
pid = wait_thr[:pid]
Process.kill("KILL", pid)
raise "Unable to execute command \"#{command}\"\nThe command took longer than #{timeout} to execute"
end
end
end

0 comments on commit ea86cea

Please sign in to comment.