Class: Autospec::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/autospec/manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Manager

Returns a new instance of Manager.



17
18
19
20
21
22
23
24
25
# File 'lib/autospec/manager.rb', line 17

def initialize(opts = {})
  @opts = opts
  @debug = opts[:debug]
  @auto_run_all = ENV["AUTO_RUN_ALL"] != "0"
  @queue = []
  @mutex = Mutex.new
  @signal = ConditionVariable.new
  @runners = [ruby_runner]
end

Class Method Details

.run(opts = {}) ⇒ Object



13
14
15
# File 'lib/autospec/manager.rb', line 13

def self.run(opts = {})
  self.new(opts).run
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/autospec/manager.rb', line 27

def run
  Signal.trap("HUP") do
    stop_runners
    exit
  end

  Signal.trap("INT") do
    begin
      stop_runners
    rescue => e
      puts "FAILED TO STOP RUNNERS #{e}"
    end
    exit
  end

  ensure_all_specs_will_run if @auto_run_all
  start_runners
  start_service_queue
  listen_for_changes

  puts "Press [ENTER] to stop the current run"
  puts "Press [ENTER] while stopped to run all specs" unless @auto_run_all
  while @runners.any?(&:running?)
    STDIN.gets
    process_queue
  end
rescue => e
  fail(e, "failed in run")
ensure
  stop_runners
end