When a Rails server starts, it lists the Puma workers by their index and PID.
[17042] - Worker 0 (PID: 17069) booted in 0.01s, phase: 0
[17042] - Worker 1 (PID: 17070) booted in 0.01s, phase: 0
I can get the PID of the worker from within the request with Process.pid.
> Process.pid
=> 17069
Is there a way to get the index of the Puma worker (0, 1, etc.) from within the request processing?
I see that the Puma::Cluster::Worker class has an index method that should get me that value, but I can't figure out how to get the instance of that class making the current request.
I believe I can get it through ObjectSpace, but I have to imagine I'm missing a better way.
> ObjectSpace.each_object(Puma::Cluster::Worker) { |x| p x.index }
0
=> 1