lib/pitchfork/worker.rb in pitchfork-0.13.0 vs lib/pitchfork/worker.rb in pitchfork-0.14.0
- old
+ new
@@ -4,11 +4,11 @@
module Pitchfork
# This class and its members can be considered a stable interface
# and will not change in a backwards-incompatible fashion between
# releases of pitchfork. Knowledge of this class is generally not
- # not needed for most users of pitchfork.
+ # needed for most users of pitchfork.
#
# Some users may want to access it in the after_worker_fork/after_mold_fork hooks.
# See the Pitchfork::Configurator RDoc for examples.
class Worker
# :stopdoc:
@@ -22,26 +22,13 @@
@generation = generation
@mold = false
@to_io = @master = nil
@exiting = false
@requests_count = 0
- if nr
- @deadline_drop = SharedMemory.worker_deadline(nr)
- self.deadline = 0
- else
- promoted!(nil)
- end
+ init_deadline
end
- def meminfo
- @meminfo ||= MemInfo.new(pid) if pid
- end
-
- def refresh
- meminfo&.update
- end
-
def exiting?
@exiting
end
def pending?
@@ -92,10 +79,14 @@
def spawn_worker(new_worker)
send_message_nonblock(Message::SpawnWorker.new(new_worker.nr))
end
+ def spawn_service(_new_service)
+ send_message_nonblock(Message::SpawnService.new)
+ end
+
def promote!(timeout)
@generation += 1
promoted!(timeout)
end
@@ -109,10 +100,14 @@
def mold?
@mold
end
+ def service?
+ false
+ end
+
def to_io # IO.select-compatible
@to_io.to_io
end
# master fakes SIGQUIT using this
@@ -218,10 +213,19 @@
@master&.close
end
private
+ def init_deadline
+ if nr
+ @deadline_drop = SharedMemory.worker_deadline(@nr)
+ self.deadline = 0
+ else
+ promoted!(nil)
+ end
+ end
+
def pipe=(socket)
raise ArgumentError, "pipe can't be nil" unless socket
Info.keep_io(socket)
@master = MessageSocket.new(socket)
end
@@ -237,8 +241,32 @@
end
rescue Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENOTCONN
# worker will be reaped soon
end
success
+ end
+ end
+
+ class Service < Worker
+ def initialize(pid: nil, generation: 0)
+ super(nil, pid: pid, generation: generation)
+ end
+
+ def service?
+ true
+ end
+
+ def register_to_master(control_socket)
+ create_socketpair!
+ message = Message::ServiceSpawned.new(@pid, generation, @master)
+ control_socket.sendmsg(message)
+ @master.close
+ end
+
+ private
+
+ def init_deadline
+ @deadline_drop = SharedMemory.service_deadline
+ self.deadline = 0
end
end
end