Module: Pitchfork::Info

Defined in:
lib/pitchfork/info.rb

Defined Under Namespace

Classes: WeakSet

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.workers_countObject

Returns the value of attribute workers_count.



33
34
35
# File 'lib/pitchfork/info.rb', line 33

def workers_count
  @workers_count
end

Class Method Details

.close_all_ios!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pitchfork/info.rb', line 45

def close_all_ios!
  ignored_ios = [$stdin, $stdout, $stderr, STDIN, STDOUT, STDERR].uniq.compact

  @kept_ios.each do |io_like|
    ignored_ios << (io_like.is_a?(IO) ? io_like : io_like.to_io)
  end

  ObjectSpace.each_object(IO) do |io|
    if io_open?(io) && io_autoclosed?(io) && !ignored_ios.include?(io)
      if io.is_a?(TCPSocket)
        # If we inherited a TCP Socket, calling #close directly could send FIN or RST.
        # So we first reopen /dev/null to avoid that.
        io.reopen(File::NULL)
      end
      begin
        io.close
      rescue Errno::EBADF
      end
    end
  end
end

.fork_safe?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/pitchfork/info.rb', line 67

def fork_safe?
  @fork_safe
end

.keep_io(io) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
# File 'lib/pitchfork/info.rb', line 35

def keep_io(io)
  raise ArgumentError, "#{io.inspect} doesn't respond to :to_io" unless io.respond_to?(:to_io)
  @kept_ios << io
  io
end

.keep_ios(ios) ⇒ Object



41
42
43
# File 'lib/pitchfork/info.rb', line 41

def keep_ios(ios)
  ios.each { |io| keep_io(io) }
end

.live_workers_countObject



75
76
77
78
79
80
# File 'lib/pitchfork/info.rb', line 75

def live_workers_count
  now = Pitchfork.time_now(true)
  (0...workers_count).count do |nr|
    SharedMemory.worker_deadline(nr).value > now
  end
end

.no_longer_fork_safe!Object



71
72
73
# File 'lib/pitchfork/info.rb', line 71

def no_longer_fork_safe!
  @fork_safe = false
end

.shutting_down?Boolean

Returns true if the server is shutting down. This can be useful to implement health check endpoints, so they can fail immediately after TERM/QUIT/INT was received by the master process. Otherwise they may succeed while Pitchfork is draining requests causing more requests to be sent.

Returns:

  • (Boolean)


88
89
90
# File 'lib/pitchfork/info.rb', line 88

def shutting_down?
  SharedMemory.shutting_down?
end