lib/pitchfork/worker.rb in pitchfork-0.10.0 vs lib/pitchfork/worker.rb in pitchfork-0.11.0
- old
+ new
@@ -25,11 +25,11 @@
@requests_count = 0
if nr
@deadline_drop = SharedMemory.worker_deadline(nr)
self.deadline = 0
else
- promoted!
+ promoted!(nil)
end
end
def meminfo
@meminfo ||= MemInfo.new(pid) if pid
@@ -53,10 +53,17 @@
def update(message)
message.class.members.each do |member|
send("#{member}=", message.public_send(member))
end
+
+ case message
+ when Message::MoldSpawned
+ @deadline_drop = SharedMemory.mold_promotion_deadline
+ when Message::MoldReady
+ @deadline_drop = SharedMemory.mold_deadline
+ end
end
def register_to_master(control_socket)
create_socketpair!
message = Message::WorkerSpawned.new(@nr, @pid, generation, @master)
@@ -73,30 +80,31 @@
def finish_promotion(control_socket)
message = Message::MoldReady.new(@nr, @pid, generation)
control_socket.sendmsg(message)
SharedMemory.current_generation = @generation
+ @deadline_drop = SharedMemory.mold_deadline
end
def promote(generation)
send_message_nonblock(Message::PromoteWorker.new(generation))
end
def spawn_worker(new_worker)
send_message_nonblock(Message::SpawnWorker.new(new_worker.nr))
end
- def promote!
+ def promote!(timeout)
@generation += 1
- promoted!
+ promoted!(timeout)
end
- def promoted!
+ def promoted!(timeout)
@mold = true
@nr = nil
- @deadline_drop = SharedMemory.mold_deadline
- self.deadline = 0
+ @deadline_drop = SharedMemory.mold_promotion_deadline
+ update_deadline(timeout) if timeout
self
end
def mold?
@mold
@@ -139,13 +147,9 @@
success
end
def hard_kill(sig)
Process.kill(sig, pid)
- end
-
- def hard_timeout!
- hard_kill(:KILL)
end
# this only runs when the Rack app.call is not running
# act like a listener
def accept_nonblock(exception: nil) # :nodoc: