Class: Honcho::Runner

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/honcho/runner.rb

Direct Known Subclasses

UIRunner

Constant Summary

Constants included from Colors

Colors::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colors

#assign_colors_for_ansi, #assign_colors_for_curses

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



14
15
16
17
18
19
20
21
22
23
# File 'lib/honcho/runner.rb', line 14

def initialize(options)
  @config_file_path = options[:config]
  @root_path = File.expand_path('..', @config_file_path)
  @running = {}
  @stopping = {}
  @redis = Redis.new
  @adapters_by_app = build_adapters
  @adapters = @adapters_by_app.values.flatten
  @colors = assign_colors_for_ansi
end

Instance Attribute Details

#adaptersObject (readonly)

Returns the value of attribute adapters.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def adapters
  @adapters
end

#adapters_by_appObject (readonly)

Returns the value of attribute adapters_by_app.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def adapters_by_app
  @adapters_by_app
end

#colorsObject (readonly)

Returns the value of attribute colors.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def colors
  @colors
end

#config_file_pathObject (readonly)

Returns the value of attribute config_file_path.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def config_file_path
  @config_file_path
end

#redisObject (readonly)

Returns the value of attribute redis.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def redis
  @redis
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def root_path
  @root_path
end

#runningObject (readonly)

Returns the value of attribute running.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def running
  @running
end

#stoppingObject (readonly)

Returns the value of attribute stopping.



25
26
27
# File 'lib/honcho/runner.rb', line 25

def stopping
  @stopping
end

Instance Method Details

#intervalObject



50
51
52
# File 'lib/honcho/runner.rb', line 50

def interval
  config['interval'] || 2
end

#log(name, message) ⇒ Object



36
37
38
39
# File 'lib/honcho/runner.rb', line 36

def log(name, message)
  color = colors[name]
  $stdout.write("\e[#{color}m#{name.rjust(label_width)}:\e[0m #{message}")
end

#runObject



27
28
29
30
31
32
33
34
# File 'lib/honcho/runner.rb', line 27

def run
  trap(:INT)  { term_all && exit }
  trap(:TERM) { term_all && exit }
  loop do
    check_for_work
    sleep(interval)
  end
end

#spawn(path, cmd, out) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/honcho/runner.rb', line 41

def spawn(path, cmd, out)
  Process.spawn(
    "cd '#{root_path}/#{path}' && " + command_template % cmd,
    pgroup: true,
    err: out,
    out: out
  )
end

#stop_delayObject



54
55
56
# File 'lib/honcho/runner.rb', line 54

def stop_delay
  config['stop_delay'] || 30
end