Class: AppUp::Shell::Runner

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/app_up/shell/runner.rb

Constant Summary collapse

MAX_PROCESS_COUNT =
8
CommandFailureError =
Class.new(StandardError)

Constants included from Color

Color::CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_path:, working_directory:, verbose: false) ⇒ Runner

Returns a new instance of Runner.



15
16
17
18
19
20
21
22
23
24
# File 'lib/app_up/shell/runner.rb', line 15

def initialize(log_path:, working_directory:, verbose: false)
  @working_directory = working_directory
  @log_path = log_path
  @verbose = verbose

  @queue = WorkQueue.new(MAX_PROCESS_COUNT, nil)

  %x{echo "" > #{log_path}}
  Dir.chdir(%x[ git rev-parse --show-toplevel ].chomp)
end

Instance Attribute Details

#log_path=(value) ⇒ Object

Sets the attribute log_path

Parameters:

  • value

    the value to set the attribute log_path to.



12
13
14
# File 'lib/app_up/shell/runner.rb', line 12

def log_path=(value)
  @log_path = value
end

#queue=(value) ⇒ Object

Sets the attribute queue

Parameters:

  • value

    the value to set the attribute queue to.



12
13
14
# File 'lib/app_up/shell/runner.rb', line 12

def queue=(value)
  @queue = value
end

#working_directory=(value) ⇒ Object

Sets the attribute working_directory

Parameters:

  • value

    the value to set the attribute working_directory to.



12
13
14
# File 'lib/app_up/shell/runner.rb', line 12

def working_directory=(value)
  @working_directory = value
end

Instance Method Details

#enqueue(method, *args, &block) ⇒ Object



49
50
51
52
53
# File 'lib/app_up/shell/runner.rb', line 49

def enqueue(method, *args, &block)
  queue.enqueue_b do
    send(method, *args, &block)
  end
end

#flushObject



55
56
57
# File 'lib/app_up/shell/runner.rb', line 55

def flush
  queue.join
end

#notify(msg) ⇒ Object



42
43
44
45
46
47
# File 'lib/app_up/shell/runner.rb', line 42

def notify(msg)
  return if @verbose

  log msg.to_s
  print "#{yellow(msg.to_s)}\n"
end

#run(cmd, dir: working_directory, &block) ⇒ Object

The block passed to run is a callback. It is used to add a dependent command to the queue.



28
29
30
31
32
33
34
35
# File 'lib/app_up/shell/runner.rb', line 28

def run(cmd, dir: working_directory, &block)
  command = "cd #{Utils::Path.relative_join(dir)} && #{cmd}"
  handle_output_for(command)

  shell_out(command).split("\n").tap do
    block.call if block_given?
  end
end

#warn(msg) ⇒ Object



37
38
39
40
# File 'lib/app_up/shell/runner.rb', line 37

def warn(msg)
  log msg.to_s
  print "#{red(msg.to_s)}\n"
end