1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Implement remote signals via heartbeat

This commit is contained in:
Mike Perham 2014-05-13 21:41:40 -07:00
parent f81f09dee4
commit b0aa136be6
6 changed files with 49 additions and 12 deletions

View file

@ -1,3 +1,20 @@
3.1.0
-----------
- New remote signals feature: you can remotely trigger Sidekiq to quiet
or terminate remotely via API, without signals. This is most useful
on Heroku which does not support the USR1 'quiet' signal. Now you can
run a rake task like this at the start of your deploy to quiet your
set of Sidekiq processes.
```ruby
namespace :sidekiq do
task :quiet => :environment do
Sidekiq::ProcessSet.new.each(&:quiet!)
end
end
```
3.0.2
-----------

View file

@ -514,6 +514,22 @@ module Sidekiq
def [](key)
@attribs[key]
end
def quiet!
key = "#{identity}-signals"
Sidekiq.redis do |c|
c.multi do
c.lpush(key, 'USR1')
c.expire(key, 60)
end
end
end
private
def identity
@id ||= "#{self['hostname']}:#{self['pid']}"
end
end
##

View file

@ -95,16 +95,6 @@ module Sidekiq
private
def fire_event(event)
Sidekiq.options[:lifecycle_events][event].each do |block|
begin
block.call
rescue => ex
handle_exception(ex, { :event => event })
end
end
end
def handle_signal(sig)
Sidekiq.logger.debug "Got #{sig} signal"
case sig

View file

@ -149,12 +149,15 @@ module Sidekiq
def (key)
begin
Sidekiq.redis do |conn|
_, _, msg = Sidekiq.redis do |conn|
conn.multi do
conn.hmset(key, 'busy', @busy.size, 'beat', Time.now.to_f)
conn.expire(key, 60)
conn.rpop("#{key}-signals")
end
end
::Process.kill(msg, $$) if msg
rescue => e
# ignore all redis/network issues
logger.error("heartbeat: #{e.message}")

View file

@ -33,5 +33,16 @@ module Sidekiq
def identity
@@identity ||= "#{hostname}:#{$$}"
end
def fire_event(event)
Sidekiq.options[:lifecycle_events][event].each do |block|
begin
block.call
rescue => ex
handle_exception(ex, { :event => event })
end
end
end
end
end

View file

@ -1,3 +1,3 @@
module Sidekiq
VERSION = "3.0.2"
VERSION = "3.1.0"
end