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:
parent
f81f09dee4
commit
b0aa136be6
6 changed files with 49 additions and 12 deletions
17
Changes.md
17
Changes.md
|
@ -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
|
3.0.2
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|
|
@ -514,6 +514,22 @@ module Sidekiq
|
||||||
def [](key)
|
def [](key)
|
||||||
@attribs[key]
|
@attribs[key]
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -95,16 +95,6 @@ module Sidekiq
|
||||||
|
|
||||||
private
|
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)
|
def handle_signal(sig)
|
||||||
Sidekiq.logger.debug "Got #{sig} signal"
|
Sidekiq.logger.debug "Got #{sig} signal"
|
||||||
case sig
|
case sig
|
||||||
|
|
|
@ -149,12 +149,15 @@ module Sidekiq
|
||||||
|
|
||||||
def ❤(key)
|
def ❤(key)
|
||||||
begin
|
begin
|
||||||
Sidekiq.redis do |conn|
|
_, _, msg = Sidekiq.redis do |conn|
|
||||||
conn.multi do
|
conn.multi do
|
||||||
conn.hmset(key, 'busy', @busy.size, 'beat', Time.now.to_f)
|
conn.hmset(key, 'busy', @busy.size, 'beat', Time.now.to_f)
|
||||||
conn.expire(key, 60)
|
conn.expire(key, 60)
|
||||||
|
conn.rpop("#{key}-signals")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
::Process.kill(msg, $$) if msg
|
||||||
rescue => e
|
rescue => e
|
||||||
# ignore all redis/network issues
|
# ignore all redis/network issues
|
||||||
logger.error("heartbeat: #{e.message}")
|
logger.error("heartbeat: #{e.message}")
|
||||||
|
|
|
@ -33,5 +33,16 @@ module Sidekiq
|
||||||
def identity
|
def identity
|
||||||
@@identity ||= "#{hostname}:#{$$}"
|
@@identity ||= "#{hostname}:#{$$}"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module Sidekiq
|
module Sidekiq
|
||||||
VERSION = "3.0.2"
|
VERSION = "3.1.0"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue