Created
August 10, 2014 20:21
Revisions
-
samsm created this gist
Aug 10, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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