Module: Execution

Instance Method Summary collapse

Instance Method Details

#fork_exec(command, _prefix = 'unknown', _color = :cyan) ⇒ Object

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



25
26
27
# 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) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



29
30
31
# File 'lib/docker-sync/execution.rb', line 29

def with_time(prefix)
  "[#{Time.now}] #{prefix}"
end