Class: RSched::ExecRunner
- Inherits:
-
Object
- Object
- RSched::ExecRunner
- Defined in:
- lib/rsched/engine.rb
Instance Method Summary collapse
- #call(ident, time, action) ⇒ Object
-
#initialize(cmd) ⇒ ExecRunner
constructor
A new instance of ExecRunner.
- #terminate ⇒ Object
Constructor Details
#initialize(cmd) ⇒ ExecRunner
Returns a new instance of ExecRunner.
269 270 271 272 273 274 |
# File 'lib/rsched/engine.rb', line 269 def initialize(cmd) @cmd = cmd + ' ' + ARGV.map {|a| Shellwords.escape(a) }.join(' ') @iobuf = '' @pid = nil @next_kill = :TERM end |
Instance Method Details
#call(ident, time, action) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rsched/engine.rb', line 276 def call(ident, time, action) = [ident, time, action].join("\t") IO.popen(@cmd, "r+") {|io| @pid = io.pid io.write() rescue nil io.close_write begin while true io.sysread(1024, @iobuf) print @iobuf end rescue EOFError end } if $?.to_i != 0 raise "Command failed" end end |
#terminate ⇒ Object
295 296 297 298 |
# File 'lib/rsched/engine.rb', line 295 def terminate Process.kill(@next_kill, @pid) @next_kill = :KILL end |