Class: Pdi::Executor
- Inherits:
-
Object
- Object
- Pdi::Executor
- Defined in:
- lib/pdi/executor.rb,
lib/pdi/executor/result.rb,
lib/pdi/executor/status.rb
Overview
This class is the library’s “metal” layer, the one which actually makes the system call and interacts with the operating system (through Ruby’s standard library.)
Defined Under Namespace
Instance Attribute Summary collapse
-
#timeout_in_seconds ⇒ Object
readonly
Returns the value of attribute timeout_in_seconds.
Instance Method Summary collapse
-
#initialize(timeout_in_seconds: nil) ⇒ Executor
constructor
A new instance of Executor.
- #run(args) ⇒ Object
Constructor Details
#initialize(timeout_in_seconds: nil) ⇒ Executor
Returns a new instance of Executor.
18 19 20 21 22 |
# File 'lib/pdi/executor.rb', line 18 def initialize(timeout_in_seconds: nil) @timeout_in_seconds = timeout_in_seconds freeze end |
Instance Attribute Details
#timeout_in_seconds ⇒ Object (readonly)
Returns the value of attribute timeout_in_seconds.
16 17 18 |
# File 'lib/pdi/executor.rb', line 16 def timeout_in_seconds @timeout_in_seconds end |
Instance Method Details
#run(args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pdi/executor.rb', line 24 def run(args) args = Array(args).map(&:to_s) IO.popen(args, err: i[child out]) do |io| begin io_read = if timeout_in_seconds Timeout.timeout(timeout_in_seconds) { io.read } else io.read end io.close status = $CHILD_STATUS Result.new( args: args, status: { code: status.exitstatus, out: io_read, pid: status.pid } ) rescue Timeout::Error => e Process.kill(9, io.pid) raise e end end end |