Class: SafeExec::PipeExecutor::TimeoutDelegate
- Inherits:
-
Object
- Object
- SafeExec::PipeExecutor::TimeoutDelegate
- Defined in:
- lib/safe_exec/pipe_executor.rb
Instance Method Summary collapse
-
#initialize(executor, timeout, exception) ⇒ TimeoutDelegate
constructor
A new instance of TimeoutDelegate.
- #run(cmd, *args) ⇒ Object
Constructor Details
#initialize(executor, timeout, exception) ⇒ TimeoutDelegate
Returns a new instance of TimeoutDelegate.
77 78 79 |
# File 'lib/safe_exec/pipe_executor.rb', line 77 def initialize(executor, timeout, exception) @executor, @timeout, @exception = executor, timeout, exception end |
Instance Method Details
#run(cmd, *args) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/safe_exec/pipe_executor.rb', line 81 def run(cmd, *args) @executor.run(cmd, *args) do |t| begin Timeout.timeout(@timeout, @exception) do yield t if block_given? t.value end rescue @exception => e begin @executor.send(:abort) Process.kill("TERM", t.pid) rescue Errno::ESRCH ensure raise e end end end end |