Module: Spring::ApplicationImpl

Included in:
Application
Defined in:
lib/spring-jruby/impl/fork/application.rb,
lib/spring-jruby/impl/pool/application.rb

Instance Method Summary collapse

Instance Method Details

#before_commandObject



65
66
67
# File 'lib/spring-jruby/impl/fork/application.rb', line 65

def before_command
  # NOP
end

#eager_preloadObject



15
16
17
# File 'lib/spring-jruby/impl/fork/application.rb', line 15

def eager_preload
  with_pty { preload }
end

#fork_child(client, streams, child_started) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/spring-jruby/impl/fork/application.rb', line 52

def fork_child(client, streams, child_started)
  pid = fork { yield }
  child_started[0] = true

  disconnect_database
  reset_streams

  log "forked #{pid}"
  manager.puts pid

  wait pid, streams, client
end

#notify_manager_readyObject



3
4
5
# File 'lib/spring-jruby/impl/fork/application.rb', line 3

def notify_manager_ready
  manager.puts
end

#receive_streams(client) ⇒ Object



7
8
9
# File 'lib/spring-jruby/impl/fork/application.rb', line 7

def receive_streams(client)
  3.times.map { IOWrapper.recv_io(client).to_io }
end

#reopen_streams(streams) ⇒ Object



11
12
13
# File 'lib/spring-jruby/impl/fork/application.rb', line 11

def reopen_streams(streams)
  [STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
end

#reset_streamsObject



28
29
30
31
# File 'lib/spring-jruby/impl/fork/application.rb', line 28

def reset_streams
  [STDOUT, STDERR].each { |stream| stream.reopen(spring_env.log_file) }
  STDIN.reopen("/dev/null")
end

#screen_attached?Boolean

Returns:



19
20
21
# File 'lib/spring-jruby/impl/pool/application.rb', line 19

def screen_attached?
  !system(%{screen -ls | grep "#{ENV['SPRING_SCREEN_NAME']}" | grep Detached > /dev/null})
end

#screen_move_to_bottomObject



23
24
25
# File 'lib/spring-jruby/impl/pool/application.rb', line 23

def screen_move_to_bottom
  puts "\033[22B"
end

#wait(pid, streams, client) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spring-jruby/impl/fork/application.rb', line 33

def wait(pid, streams, client)
  @mutex.synchronize { @waiting << pid }

  # Wait in a separate thread so we can run multiple commands at once
  Thread.new {
    begin
      _, status = Process.wait2 pid
      log "#{pid} exited with #{status.exitstatus}"

      streams.each(&:close)
      client.puts(status.exitstatus)
      client.close
    ensure
      @mutex.synchronize { @waiting.delete pid }
      exit_if_finished
    end
  }
end

#with_ptyObject



19
20
21
22
23
24
25
26
# File 'lib/spring-jruby/impl/fork/application.rb', line 19

def with_pty
  PTY.open do |master, slave|
    [STDOUT, STDERR, STDIN].each { |s| s.reopen slave }
    Thread.new { master.read }
    yield
    reset_streams
  end
end