Skip to content

Instantly share code, notes, and snippets.

@samsm
Created August 10, 2014 20:21
Show Gist options
  • Save samsm/d05203adc8c4c89ca829 to your computer and use it in GitHub Desktop.
Save samsm/d05203adc8c4c89ca829 to your computer and use it in GitHub Desktop.
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
@seuros
Copy link

seuros commented Aug 10, 2014

I don't think you need the initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment