Class: Honcho::Runner
Direct Known Subclasses
Constant Summary
Constants included from Colors
Instance Attribute Summary collapse
-
#adapters ⇒ Object
readonly
Returns the value of attribute adapters.
-
#adapters_by_app ⇒ Object
readonly
Returns the value of attribute adapters_by_app.
-
#colors ⇒ Object
readonly
Returns the value of attribute colors.
-
#config_file_path ⇒ Object
readonly
Returns the value of attribute config_file_path.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#stopping ⇒ Object
readonly
Returns the value of attribute stopping.
Instance Method Summary collapse
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #interval ⇒ Object
- #log(name, message) ⇒ Object
- #run ⇒ Object
- #spawn(path, cmd, out) ⇒ Object
- #stop_delay ⇒ Object
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() @config_file_path = [:config] @root_path = File.('..', @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
#adapters ⇒ Object (readonly)
Returns the value of attribute adapters.
25 26 27 |
# File 'lib/honcho/runner.rb', line 25 def adapters @adapters end |
#adapters_by_app ⇒ Object (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 |
#colors ⇒ Object (readonly)
Returns the value of attribute colors.
25 26 27 |
# File 'lib/honcho/runner.rb', line 25 def colors @colors end |
#config_file_path ⇒ Object (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 |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
25 26 27 |
# File 'lib/honcho/runner.rb', line 25 def redis @redis end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
25 26 27 |
# File 'lib/honcho/runner.rb', line 25 def root_path @root_path end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
25 26 27 |
# File 'lib/honcho/runner.rb', line 25 def running @running end |
#stopping ⇒ Object (readonly)
Returns the value of attribute stopping.
25 26 27 |
# File 'lib/honcho/runner.rb', line 25 def stopping @stopping end |
Instance Method Details
#interval ⇒ Object
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, ) color = colors[name] $stdout.write("\e[#{color}m#{name.rjust(label_width)}:\e[0m #{}") end |
#run ⇒ Object
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_delay ⇒ Object
54 55 56 |
# File 'lib/honcho/runner.rb', line 54 def stop_delay config['stop_delay'] || 30 end |