Resque: Work off queues manually

Updated . Posted . Visible to the public.

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
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2011-07-24 19:37)