Class: RSched::ExecRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rsched/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ ExecRunner

Returns a new instance of ExecRunner.



264
265
266
267
268
269
# File 'lib/rsched/engine.rb', line 264

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



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/rsched/engine.rb', line 271

def call(ident, time, action)
  message = [ident, time, action].join("\t")
  IO.popen(@cmd, "r+") {|io|
    @pid = io.pid
    io.write(message) 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

#terminateObject



290
291
292
293
# File 'lib/rsched/engine.rb', line 290

def terminate
  Process.kill(@next_kill, @pid)
  @next_kill = :KILL
end