Class: RackCheck::ServerManager

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rack_check/server_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#with_environment

Constructor Details

#initialize(context, ru_file) ⇒ ServerManager

Returns a new instance of ServerManager.



11
12
13
14
15
# File 'lib/rack_check/server_manager.rb', line 11

def initialize(context, ru_file)
  @ru_file = ru_file
  @stop_var = Concurrent::MVar.new
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/rack_check/server_manager.rb', line 9

def context
  @context
end

#ru_fileObject (readonly)

Returns the value of attribute ru_file.



9
10
11
# File 'lib/rack_check/server_manager.rb', line 9

def ru_file
  @ru_file
end

Instance Method Details

#errorsObject



46
47
48
# File 'lib/rack_check/server_manager.rb', line 46

def errors
  @err&.read.strip
end

#outputObject



50
51
52
# File 'lib/rack_check/server_manager.rb', line 50

def output
  @out&.read.strip
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rack_check/server_manager.rb', line 17

def run
  Thread.new do
    begin
      with_environment(ru_file) do |dir|
        Dir.chdir(dir) do
          @pid, @in, @out, @err = Open4.popen4 context.app_server_command
          @stop_var.take
          Process.kill 'TERM', @pid
          Process.wait @pid
          @pid = nil
        end
      end
    rescue => e
      $stderr.puts "App server thread exited: #{e.message}\n#{e.backtrace.join("\n")}"
    end
  end

  port = wait_for_port

  "http://localhost:#{port}"
end

#stopObject



39
40
41
42
43
44
# File 'lib/rack_check/server_manager.rb', line 39

def stop
  @stop_var.put true
  while check_port
    sleep 0.1
  end
end