class Webtask::TaskRunner
Attributes
command[R]
out[R]
Public Class Methods
new(command:, out:)
click to toggle source
# File lib/webtask/task_runner.rb, line 10 def initialize(command:, out:) @command = command @out = out end
run(command:, out:)
click to toggle source
# File lib/webtask/task_runner.rb, line 4 def run(command:, out:) runner = new(command: command, out: out) runner.run end
Public Instance Methods
run()
click to toggle source
# File lib/webtask/task_runner.rb, line 15 def run print_intro execute_command print_outro end
Private Instance Methods
execute_command()
click to toggle source
# File lib/webtask/task_runner.rb, line 38 def execute_command Open3.popen3(command) do |_stdin, stdout, stderr, thread| # read each stream from a new thread { out: stdout, err: stderr }.each do |key, io| Thread.new do until (raw_line = io.gets).nil? do outputs[key].write [Time.now, raw_line].join(" - ") end end end thread.join # don't exit until the external process is done end end
outputs()
click to toggle source
# File lib/webtask/task_runner.rb, line 29 def outputs @outputs ||= { err: StreamError.new(out), out: StreamOut.new(out) } end
print_intro()
click to toggle source
# File lib/webtask/task_runner.rb, line 33 def print_intro outputs[:out].write(">>> Running #{command.inspect}...") outputs[:out].write("\n") end
print_outro()
click to toggle source
# File lib/webtask/task_runner.rb, line 53 def print_outro outputs[:out].write("\n") if outputs[:err].errors? outputs[:err].write("There have been errors!") else outputs[:out].write("All Done!") end end