class Honcho::Runner
Attributes
adapters[R]
adapters_by_app[R]
colors[R]
config_file_path[R]
redis[R]
root_path[R]
running[R]
stopping[R]
Public Class Methods
new(options)
click to toggle source
# 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
Public Instance Methods
interval()
click to toggle source
# File lib/honcho/runner.rb, line 51 def interval config['interval'] || 2 end
log(name, message)
click to toggle source
# 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
run()
click to toggle source
# 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)
click to toggle source
# File lib/honcho/runner.rb, line 41 def spawn(path, cmd, out) Process.spawn( { 'RBENV_VERSION' => nil, 'RBENV_GEMSET_ALREADY' => nil, 'RBENV_DIR' => nil }, "cd '#{root_path}/#{path}' && " + command_template % cmd, pgroup: true, err: out, out: out ) end
stop_delay()
click to toggle source
# File lib/honcho/runner.rb, line 55 def stop_delay config['stop_delay'] || 30 end
Private Instance Methods
apps()
click to toggle source
# File lib/honcho/runner.rb, line 61 def apps config['apps'] end
build_adapter(app, config, type, worker_config)
click to toggle source
# File lib/honcho/runner.rb, line 93 def build_adapter(app, config, type, worker_config) adapter = Adapters.from_type(type) return if adapter.nil? adapter.new( config: worker_config.merge('name' => app, 'path' => config['path']), redis: redis, runner: self ) end
build_adapters()
click to toggle source
# File lib/honcho/runner.rb, line 85 def build_adapters apps.each_with_object({}) do |(app, config), hash| hash[app] = config.map do |type, worker_config| build_adapter(app, config, type, worker_config) end.compact end end
check_for_work()
click to toggle source
# File lib/honcho/runner.rb, line 73 def check_for_work adapters.each(&:check_for_work) end
command_template()
click to toggle source
# File lib/honcho/runner.rb, line 65 def command_template config['command_template'] || '%s' end
config()
click to toggle source
# File lib/honcho/runner.rb, line 69 def config @config ||= YAML.load_file(config_file_path) end
label_width()
click to toggle source
# File lib/honcho/runner.rb, line 81 def label_width @label_width ||= apps.keys.map(&:size).max end
term_all()
click to toggle source
# File lib/honcho/runner.rb, line 77 def term_all adapters.each(&:really_stop) end