mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Process.pid does not work on Heroku, #22
This commit is contained in:
parent
ac5d879361
commit
2c83b74f27
3 changed files with 18 additions and 4 deletions
|
@ -45,10 +45,8 @@ module Sidekiq
|
||||||
|
|
||||||
redis.with_connection do |conn|
|
redis.with_connection do |conn|
|
||||||
workers = conn.smembers('workers')
|
workers = conn.smembers('workers')
|
||||||
logger.info "My tag: ':#{Process.pid}-'"
|
|
||||||
logger.info "Current workers: #{workers.inspect}"
|
|
||||||
workers.each do |name|
|
workers.each do |name|
|
||||||
conn.srem('workers', name) if name =~ /:#{Process.pid}-/
|
conn.srem('workers', name) if name =~ /:#{process_id}-/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@str ||= "#{hostname}:#{Process.pid}-#{Thread.current.object_id}:default"
|
@str ||= "#{hostname}:#{process_id}-#{Thread.current.object_id}:default"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -41,5 +41,21 @@ module Sidekiq
|
||||||
def redis
|
def redis
|
||||||
Sidekiq::Manager.redis
|
Sidekiq::Manager.redis
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_id
|
||||||
|
Sidekiq::Util.process_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.process_id
|
||||||
|
@pid ||= begin
|
||||||
|
if Process.pid == 1
|
||||||
|
# Heroku does not expose pids.
|
||||||
|
require 'securerandom'
|
||||||
|
(SecureRandom.random_number * 4_000_000_000).floor.to_s(16)
|
||||||
|
else
|
||||||
|
Process.pid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue