Module: Bridgetown::Utils::Aux

Extended by:
Inclusive::Class
Defined in:
bridgetown-core/lib/bridgetown-core/utils/aux.rb

Class Method Summary collapse

Class Method Details

.kill_processesObject



48
49
50
51
52
53
54
55
56
57
# File 'bridgetown-core/lib/bridgetown-core/utils/aux.rb', line 48

def kill_processes
  Bridgetown.logger.info "Stopping auxiliary processes..."

  utils.read_pidfile(:aux).each do |pid|
    Process.kill("SIGTERM", -Process.getpgid(pid.to_i))
  rescue Errno::ESRCH, Errno::EPERM, Errno::ECHILD # rubocop:disable Lint/SuppressedException
  ensure
    utils.remove_pidfile :aux
  end
end

.run_process(name, color, cmd, env: {}) ⇒ Object

rubocop:disable Metrics/AbcSize



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'bridgetown-core/lib/bridgetown-core/utils/aux.rb', line 22

def run_process(name, color, cmd, env: {}) # rubocop:disable Metrics/AbcSize
  @mutex ||= Thread::Mutex.new

  Thread.new do
    rd, wr = IO.pipe("BINARY")
    pid = Process.spawn({ "BRIDGETOWN_NO_BUNDLER_REQUIRE" => nil }.merge(env),
                        cmd, out: wr, err: wr, pgroup: true)
    @mutex.synchronize { utils.add_pid(pid, file: :aux) }

    loop do
      line = rd.gets
      line.to_s.lines.map(&:chomp).each do |message|
        next if name == "Frontend" && %r{ELIFECYCLE.*?Command failed}.match?(message)

        output = +""
        output << with_color(color, "[#{name}] ") if color
        output << message
        @mutex.synchronize do
          $stdout.puts output
          $stdout.flush
        end
      end
    end
  end
end

.utilsObject

Returns [Bridgetown::Foundation::Packages::Ansi, Bridgetown::Foundation::Packages::PidTracker].

Returns:

  • [Bridgetown::Foundation::Packages::Ansi, Bridgetown::Foundation::Packages::PidTracker]



11
12
13
14
# File 'bridgetown-core/lib/bridgetown-core/utils/aux.rb', line 11

packages def utils = [
  Bridgetown::Foundation::Packages::Ansi,
  Bridgetown::Foundation::Packages::PidTracker,
]

.with_color(name, message) ⇒ Object



16
17
18
19
20
# File 'bridgetown-core/lib/bridgetown-core/utils/aux.rb', line 16

def with_color(name, message)
  return message unless !name.nil? && utils.colors[name.to_sym]

  utils.send(name, message)
end