Read more

Resque: Work off queues manually

Tobias Kraze
July 24, 2011Software engineer at makandra GmbH

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.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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
Posted by Tobias Kraze to makandra dev (2011-07-24 21:37)