Class: Flatware::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/flatware/cli.rb

Overview

shared flatware cli

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.processorsObject



10
11
12
# File 'lib/flatware/cli.rb', line 10

def self.processors
  @processors ||= Etc.nprocessors
end

.worker_optionObject



14
15
16
17
18
19
20
21
22
# File 'lib/flatware/cli.rb', line 14

def self.worker_option
  method_option(
    :workers,
    aliases: '-w',
    type: :numeric,
    default: processors,
    desc: 'Number of concurrent processes to run'
  )
end

Instance Method Details

#clearObject



49
50
51
52
53
# File 'lib/flatware/cli.rb', line 49

def clear
  (Flatware.pids - [Process.pid]).each do |pid|
    Process.kill 6, pid
  end
end

#fan(*command) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flatware/cli.rb', line 33

def fan(*command)
  Flatware.verbose = options[:log]

  command = command.join(' ')
  puts "Running '#{command}' on #{workers} workers"

  workers.times do |i|
    fork do
      exec({ 'TEST_ENV_NUMBER' => i.to_s }, command)
    end
  end
  success = Process.waitall.all? { |_pid, status| status.success? }
  exit success ? 0 : 1
end