Module: Resque::Pool::PooledWorker

Defined in:
lib/resque/pool/pooled_worker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pool_master_pidObject

Returns the value of attribute pool_master_pid.



5
6
7
# File 'lib/resque/pool/pooled_worker.rb', line 5

def pool_master_pid
  @pool_master_pid
end

#worker_parent_pidObject

Returns the value of attribute worker_parent_pid.



6
7
8
# File 'lib/resque/pool/pooled_worker.rb', line 6

def worker_parent_pid
  @worker_parent_pid
end

Class Method Details

.included(base) ⇒ Object



29
30
31
32
33
34
# File 'lib/resque/pool/pooled_worker.rb', line 29

def self.included(base)
  base.instance_eval do
    alias_method :shutdown_without_pool?, :shutdown?
    alias_method :shutdown?, :shutdown_with_pool?
  end
end

Instance Method Details

#pool_master_has_gone_away?Boolean

We will return false if there are no potential_parent_pids, because that means we aren’t even running inside resque-pool.

We can’t just check if we’ve been re-parented to PID 1 (init) because we want to support docker (which will make the pool master PID 1).

We also check the worker_parent_pid, because resque-multi-jobs-fork calls Worker#shutdown? from inside the worker child process.

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/resque/pool/pooled_worker.rb', line 16

def pool_master_has_gone_away?
  pids = potential_parent_pids
  pids.any? && !pids.include?(Process.ppid)
end

#potential_parent_pidsObject



21
22
23
# File 'lib/resque/pool/pooled_worker.rb', line 21

def potential_parent_pids
  [pool_master_pid, worker_parent_pid].compact
end

#shutdown_with_pool?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/resque/pool/pooled_worker.rb', line 25

def shutdown_with_pool?
  shutdown_without_pool? || pool_master_has_gone_away?
end