Class: SolidQueue::Processes::BootGuards::ForkGuard
- Inherits:
-
Object
- Object
- SolidQueue::Processes::BootGuards::ForkGuard
- Defined in:
- lib/solid_queue/processes/runnable.rb
Overview
Tracks a forked process from the moment it's started until its boot callbacks finish, over a pipe that survives forking: the forked process writes to it when it's done booting, and its supervisor reads from it to decide whether the process is taking too long to boot and needs replacing.
Instance Method Summary collapse
- #close ⇒ Object
-
#complete ⇒ Object
Runs in the forked process when it has finished booting.
-
#completed? ⇒ Boolean
A byte means boot completed; EOF means the process exited before finishing its boot, and will be replaced when it's reaped.
-
#initialize ⇒ ForkGuard
constructor
A new instance of ForkGuard.
-
#start ⇒ Object
Runs in the parent process right after forking.
- #timed_out? ⇒ Boolean
Constructor Details
#initialize ⇒ ForkGuard
Returns a new instance of ForkGuard.
137 138 139 140 |
# File 'lib/solid_queue/processes/runnable.rb', line 137 def initialize @reader, @writer = IO.pipe @created_at = SolidQueue::Timer.monotonic_time_now end |
Instance Method Details
#close ⇒ Object
171 172 173 174 |
# File 'lib/solid_queue/processes/runnable.rb', line 171 def close reader.close unless reader.closed? writer.close unless writer.closed? end |
#complete ⇒ Object
Runs in the forked process when it has finished booting
143 144 145 146 147 148 149 150 |
# File 'lib/solid_queue/processes/runnable.rb', line 143 def complete reader.close writer.write(".") rescue Errno::EPIPE # The supervisor stopped waiting while this process finished booting ensure writer.close end |
#completed? ⇒ Boolean
A byte means boot completed; EOF means the process exited before finishing its boot, and will be replaced when it's reaped
159 160 161 162 163 164 165 |
# File 'lib/solid_queue/processes/runnable.rb', line 159 def completed? @completed ||= begin completed = reader.read_nonblock(1, exception: false) != :wait_readable reader.close if completed completed end end |
#start ⇒ Object
Runs in the parent process right after forking
153 154 155 |
# File 'lib/solid_queue/processes/runnable.rb', line 153 def start writer.close end |
#timed_out? ⇒ Boolean
167 168 169 |
# File 'lib/solid_queue/processes/runnable.rb', line 167 def timed_out? !completed? && SolidQueue::Timer.monotonic_time_now - created_at >= SolidQueue.fork_boot_timeout end |