ryandotsmith/queue_classic — Issue #27: Using QC with Rails & RSpec
Author: gerry3
Created: 2011-11-30 03:37:17+00:00
State: open

In order to get our specs working once we switched from DelayedJob to QC, I created a helper module:

module QueueClassicSpecHelper
QUEUES = [QC, $nightly_jobs]

def work_all_background_jobs
QUEUES.each do |queue|
work_queue queue
end
end

def clear_all_background_jobs
QUEUES.each do |queue|
clear_queue queue
end
end

private

def work_queue(queue)
while queue.length > 0
job = queue.dequeue
begin
job.work
rescue Object => e
raise e
ensure
queue.delete(job)
end
end
end

def clear_queue(queue)
queue.delete_all
end
end

where `work_queue` was mostly a copy from QC itself. This will probably need to be updated once we upgrade which introduces a somewhat annoying dependency.

Is there a better approach? Could something be added into QC so that it's easy to use with specs that need to run or delete jobs?