Created
August 10, 2014 20:21
-
-
Save samsm/d05203adc8c4c89ca829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuitWhenEmpty | |
def initialize(options=nil) | |
end | |
def call(worker, msg, queue) | |
yield | |
stop_disposible_worker_if_queue_empty! | |
end | |
private | |
def stop_disposible_worker_if_queue_empty! | |
if kill_when_queue_empty? | |
my_process.stop! if queue_empty? | |
end | |
end | |
def kill_when_queue_empty? | |
ENV["SIDEKIQ_KILL_WHEN_QUEUE_EMPTY"] | |
end | |
def my_process | |
ps = Sidekiq::ProcessSet.new | |
ps.detect {|p| Process.pid == p['pid'] } | |
end | |
def queue_empty? | |
Sidekiq::Queue.new.size == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think you need the initializer