Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allowing enqueue_at to call #scheduled to a class when Resque.inline …

…is true.
  • Loading branch information...
commit b2621484721d8e6c6fca8c2f4234f22e64376fe3 1 parent 8899079
@jonhyman jonhyman authored
View
8 lib/resque_scheduler.rb
@@ -123,7 +123,13 @@ def enqueue_at_with_queue(queue, timestamp, klass, *args)
if Resque.inline?
# Just create the job and let resque perform it right away with inline.
- Resque::Job.create(queue, klass, *args)
+ # If the class is a custom job class, call self#scheduled on it. This allows you to do things like
+ # Resque.enqueue_at(timestamp, CustomJobClass, :opt1 => val1). Otherwise, pass off to Resque.
+ if klass.respond_to?(:scheduled)
+ klass.scheduled(queue, klass.to_s(), *args)
+ else
+ Resque::Job.create(queue, klass, *args)
+ end
else
delayed_push(timestamp, job_to_hash_with_queue(queue, klass, args))
end
View
12 test/delayed_queue_test.rb
@@ -191,6 +191,18 @@
Resque::Scheduler.handle_delayed_items
end
+ test "when Resque.inline = true, calls klass#scheduled when enqueuing jobs if it exists" do
+ old_val = Resque.inline
+ begin
+ Resque.inline = true
+ t = Time.now - 60
+ FakeCustomJobClassEnqueueAt.expects(:scheduled).once.with(:test, FakeCustomJobClassEnqueueAt.to_s, {:foo => "bar"})
+ Resque.enqueue_at(t, FakeCustomJobClassEnqueueAt, :foo => "bar")
+ ensure
+ Resque.inline = old_val
+ end
+ end
+
test "enqueue_delayed_items_for_timestamp creates jobs and empties the delayed queue" do
t = Time.now + 60
View
7 test/redis-test.conf
@@ -106,10 +106,3 @@ databases 16
# errors for write operations, and this may even lead to DB inconsistency.
# maxmemory <bytes>
-
-############################### ADVANCED CONFIG ###############################
-
-# Glue small output buffers together in order to send small replies in a
-# single TCP packet. Uses a bit more CPU but most of the times it is a win
-# in terms of number of queries per second. Use 'yes' if unsure.
-glueoutputbuf yes
Please sign in to comment.
Something went wrong with that request. Please try again.