Module: Hydra::Derivatives::ShellBasedProcessor::ClassMethods
- Defined in:
- lib/hydra/derivatives/shell_based_processor.rb
Instance Method Summary collapse
- #execute(command) ⇒ Object
- #execute_with_timeout(timeout, command, context) ⇒ Object
- #execute_without_timeout(command, context) ⇒ Object
Instance Method Details
#execute(command) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/hydra/derivatives/shell_based_processor.rb', line 45 def execute(command) context = {} if timeout execute_with_timeout(timeout, command, context) else execute_without_timeout(command, context) end end |
#execute_with_timeout(timeout, command, context) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hydra/derivatives/shell_based_processor.rb', line 54 def execute_with_timeout(timeout, command, context) begin status = Timeout::timeout(timeout) do execute_without_timeout(command, context) end rescue Timeout::Error => ex pid = context[:pid] Process.kill("KILL", pid) raise Hydra::Derivatives::TimeoutError, "Unable to execute command \"#{command}\"\nThe command took longer than #{timeout} seconds to execute" end end |
#execute_without_timeout(command, context) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hydra/derivatives/shell_based_processor.rb', line 67 def execute_without_timeout(command, context) stdin, stdout, stderr, wait_thr = popen3(command) context[:pid] = wait_thr[:pid] 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 |