Module: NpmPipelineRails::Utils

Defined in:
lib/npm-pipeline-rails/railtie.rb

Class Method Summary collapse

Class Method Details

.background(name, &blk) ⇒ Object

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



23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



12
13
14
15
16
17
18
19
# 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) ⇒ Object



8
9
10
# File 'lib/npm-pipeline-rails/railtie.rb', line 8

def log(str)
  ::Rails.logger.debug "[npm-pipeline-rails] #{str}"
end