module NpmPipelineRails::Utils

Public Instance Methods

background(name, &blk) click to toggle source

Runs a block in the background. When the parent exits, the child will be asked to exit as well.

# File lib/npm-pipeline-rails/railtie.rb, line 23
def background(name, &blk)
  pid = fork(&blk)

  at_exit do
    Utils.log "Terminating '#{name}' [#{pid}]"
    begin
      Process.kill 'TERM', pid
      Process.wait pid
    rescue Errno::ESRCH, Errno::ECHILD => e
      Utils.log "'#{name}' [#{pid}] already dead (#{e.class})"
    end
  end
end
do_system(commands) click to toggle source
# File lib/npm-pipeline-rails/railtie.rb, line 12
def do_system(commands)
  [*commands].each do |cmd|
    Utils.log "starting '#{cmd}'"
    system cmd
    Utils.log "'#{cmd}' exited with #{$?.exitstatus} status"
    exit $?.exitstatus unless $?.exitstatus == 0
  end
end
log(str) click to toggle source
# File lib/npm-pipeline-rails/railtie.rb, line 8
def log(str)
  ::Rails.logger.debug "[npm-pipeline-rails] #{str}"
end