From 812b0ed29e0ccd303f32fc95427d08907933f972 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 17 Feb 2014 22:57:43 -0500 Subject: [PATCH] Correcting the forward-porting of #365 as it was (whoopsie!) lost in a rebase. --- lib/resque/scheduler/extension.rb | 9 +++++++++ test/delayed_queue_test.rb | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/resque/scheduler/extension.rb b/lib/resque/scheduler/extension.rb index 6564252c..7f922b04 100644 --- a/lib/resque/scheduler/extension.rb +++ b/lib/resque/scheduler/extension.rb @@ -347,6 +347,15 @@ def count_all_scheduled_jobs total_jobs end + # Discover if a job has been delayed. + # Examples + # Resque.delayed?(MyJob) + # Resque.delayed?(MyJob, id: 1) + # Returns true if the job has been delayed + def delayed?(klass, *args) + !scheduled_at(klass, *args).empty? + end + # Returns delayed jobs schedule timestamp for +klass+, +args+. def scheduled_at(klass, *args) search = encode(job_to_hash(klass, args)) diff --git a/test/delayed_queue_test.rb b/test/delayed_queue_test.rb index d99f468b..cafde507 100644 --- a/test/delayed_queue_test.rb +++ b/test/delayed_queue_test.rb @@ -534,10 +534,10 @@ Resque.enqueue_at Time.now + 1, SomeIvarJob Resque.enqueue_at Time.now + 1, SomeIvarJob, id: 1 - assert(Resque.delayed?(SomeIvarJob, id: 1)) - assert(!Resque.delayed?(SomeIvarJob, id: 2)) - assert(Resque.delayed?(SomeIvarJob)) - assert(!Resque.delayed?(SomeJob)) + assert Resque.delayed?(SomeIvarJob, id: 1) + assert !Resque.delayed?(SomeIvarJob, id: 2) + assert Resque.delayed?(SomeIvarJob) + assert !Resque.delayed?(SomeJob) end