Resque: Work off queues manually

If you're writing a spec for an application using Resque Show archive.org snapshot , you may need to work off queues manually without having an external worker running.

For this, you could use ResqueSpec Show archive.org snapshot which basically stubs away Resque completely.

If you don't want that, but more closely mimic what actually happens, use this instead:

module Resque

  def self.work_off(*queues)
    if queues.any? { |queue| peek(queue) }
      worker = Worker.new(*queues)
      worker.cant_fork = true
      worker.work do
        unless queues.any? { |queue| peek(queue) }
          worker.shutdown
        end
      end
    end
  end

end
Tobias Kraze Almost 13 years ago