test/test_helper.rb in resque-retry-1.1.4 vs test/test_helper.rb in resque-retry-1.2.0
- old
+ new
@@ -51,9 +51,37 @@
return unless job = worker.reserve
worker.perform(job, &block)
worker.done_working
end
+ def perform_next_job_fail_on_reconnect(worker,&block)
+ raise "No work for #{worker}" unless job = worker.reserve
+ worker.working_on job
+
+ # Similar to resque's Worker.work and Worker.process methods
+ begin
+ raise 'error from perform_next_job_fail_on_reconnect'
+ worker.perform(job, &block)
+ rescue Exception => exception
+ worker.report_failed_job(job, exception)
+ ensure
+ worker.done_working
+ end
+ end
+
+ def delayed_jobs
+ # The double-checks here are so that we won't blow up if the config stops using redis-namespace
+ timestamps = Resque.redis.zrange("resque:delayed_queue_schedule", 0, -1) +
+ Resque.redis.zrange("delayed_queue_schedule", 0, -1)
+
+ delayed_jobs_as_json = timestamps.map do |timestamp|
+ Resque.redis.lrange("resque:delayed:#{timestamp}", 0, -1) +
+ Resque.redis.lrange("delayed:#{timestamp}", 0, -1)
+ end.flatten
+
+ delayed_jobs_as_json.map { |json| JSON.parse(json) }
+ end
+
def clean_perform_job(klass, *args)
Resque.redis.flushall
Resque.enqueue(klass, *args)
worker = Resque::Worker.new(:testing)
perform_next_job(worker)