Permalink
Browse files

Added wrapper for Resque.enqueue_in

As provided by ResqueScheduler, this enqueues a job by a relative
time rather than an absolute time, a-la:

  Resque.enqueue_in(1.hour, SomeJob, 'an argument')
  • Loading branch information...
1 parent 6289bee commit 6a57cf91aaea04ba93669e636f03472d1608d684 @ess ess committed Jun 8, 2011
Showing with 32 additions and 0 deletions.
  1. +8 −0 lib/resque_spec/scheduler.rb
  2. +24 −0 spec/resque_spec/scheduler_spec.rb
@@ -5,12 +5,20 @@ module SchedulerExt
def enqueue_at(time, klass, *args)
ResqueSpec.enqueue_at(time, klass, *args)
end
+
+ def enqueue_in(time, klass, *args)
+ ResqueSpec.enqueue_in(time, klass, *args)
+ end
end
def enqueue_at(time, klass, *args)
store(schedule_queue_name(klass), klass, { :class => klass.to_s, :time => time, :args => args })
end
+ def enqueue_in(time, klass, *args)
+ enqueue_at(Time.now + time, klass, *args)
+ end
+
def schedule_for(klass)
queues[schedule_queue_name(klass)]
end
@@ -9,6 +9,7 @@
let(:first_name) { 'Les' }
let(:last_name) { 'Hill' }
let(:scheduled_at) { Time.now + 5 * 60 }
+ let(:scheduled_in) { 5 * 60 }
describe "#schedule_for" do
it "raises if there is no schedule queue defined for a class" do
@@ -68,5 +69,28 @@
end
end
+
+ describe "#enqueue_in" do
+ before do
+ Timecop.freeze(Time.now)
+ Resque.enqueue_in(scheduled_in, NameFromClassMethod, 1)
+ end
+
+ after do
+ Timecop.return
+ end
+
+ it "adds to the scheduled queue hash" do
+ ResqueSpec.schedule_for(NameFromClassMethod).should_not be_empty
+ end
+
+ it "sets the klass on the queue" do
+ ResqueSpec.schedule_for(NameFromClassMethod).first.should include(:class => NameFromClassMethod.to_s)
+ end
+
+ it "sets the arguments on the queue" do
+ ResqueSpec.schedule_for(NameFromClassMethod).first.should include(:time => Time.now + scheduled_in)
+ end
+ end
end
end

0 comments on commit 6a57cf9

Please sign in to comment.