diff --git a/AUTHORS.md b/AUTHORS.md index eba619aa..634f76df 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -3,6 +3,7 @@ Resque Scheduler authors - Aaron Suggs - Alexander Simonov +- Andrea Campolonghi - Ben VandenBos - Bernerd Schaefer - Bogdan Gusiev diff --git a/lib/resque_scheduler.rb b/lib/resque_scheduler.rb index 5d8af297..316105db 100644 --- a/lib/resque_scheduler.rb +++ b/lib/resque_scheduler.rb @@ -344,6 +344,15 @@ def count_all_scheduled_jobs total_jobs end + # Discover if a job hs 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 08b51276..d99f468b 100644 --- a/test/delayed_queue_test.rb +++ b/test/delayed_queue_test.rb @@ -529,4 +529,16 @@ Resque.inline = false end end + + test 'delayed?' do + 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)) + + end + end