Skip to content

Commit

Permalink
Merge pull request resque#365 from andreacfm/master
Browse files Browse the repository at this point in the history
Add Resque.delayed?
  • Loading branch information
Matteo Centenaro committed Feb 17, 2014
2 parents 2330e33 + d54ff32 commit e0e91aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Resque Scheduler authors

- Aaron Suggs
- Alexander Simonov
- Andrea Campolonghi
- Ben VandenBos
- Bernerd Schaefer
- Bogdan Gusiev
Expand Down
9 changes: 9 additions & 0 deletions lib/resque_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions test/delayed_queue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e0e91aa

Please sign in to comment.