module Execution

Public Instance Methods

fork_exec(command, _prefix = 'unknown', _color = :cyan) click to toggle source

unison doesn't work when ran in a new thread this functions creates a full new process instead

# File lib/docker-sync/execution.rb, line 25
def fork_exec(command, _prefix = 'unknown', _color = :cyan)
  Process.fork  { `#{command}` || raise(command + ' failed') }
end
thread_exec(command, prefix = 'unknown', color = :cyan) click to toggle source
# File lib/docker-sync/execution.rb, line 7
def thread_exec(command, prefix = 'unknown', color = :cyan)
  Thread.new do
    Open3.popen3(command) do |_, stdout, stderr, _|
      # noinspection RubyAssignmentExpressionInConditionalInspection
      while line_out = stdout.gets
        say_status with_time(prefix), line_out, color
      end

      # noinspection RubyAssignmentExpressionInConditionalInspection
      while line_err = stderr.gets
        say_status with_time(prefix), line_err, :red
      end
    end
  end
end
with_time(prefix) click to toggle source
# File lib/docker-sync/execution.rb, line 29
def with_time(prefix)
  "[#{Time.now}] #{prefix}"
end