Module: Pitchfork::Info
- Defined in:
- lib/pitchfork/info.rb
Defined Under Namespace
Classes: WeakSet
Class Attribute Summary collapse
-
.workers_count ⇒ Object
Returns the value of attribute workers_count.
Class Method Summary collapse
- .close_all_ios! ⇒ Object
- .fork_safe? ⇒ Boolean
- .keep_io(io) ⇒ Object
- .keep_ios(ios) ⇒ Object
- .live_workers_count ⇒ Object
- .no_longer_fork_safe! ⇒ Object
-
.shutting_down? ⇒ Boolean
Returns true if the server is shutting down.
Class Attribute Details
.workers_count ⇒ Object
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
67 68 69 |
# File 'lib/pitchfork/info.rb', line 67 def fork_safe? @fork_safe end |
.keep_io(io) ⇒ Object
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_count ⇒ Object
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.
88 89 90 |
# File 'lib/pitchfork/info.rb', line 88 def shutting_down? SharedMemory.shutting_down? end |