From f2a1e12de1a0e56178dcec5510fe870ff1248aa6 Mon Sep 17 00:00:00 2001 From: trogdoro Date: Tue, 19 Jul 2011 14:05:08 -0700 Subject: [PATCH] Added `Resque.enqueue_to`. Allows you to specify the queue and still run hooks. --- lib/resque.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/resque.rb b/lib/resque.rb index 0c4b18ede..10b1b0735 100644 --- a/lib/resque.rb +++ b/lib/resque.rb @@ -222,18 +222,31 @@ def watch_queue(queue) # # If no queue can be inferred this method will raise a `Resque::NoQueueError` # - # Returns true if the job was queued, nil if the job was rejected by a + # Returns true if the job was queued, nil if the job was rejected by a # before_enqueue hook. # # This method is considered part of the `stable` API. def enqueue(klass, *args) + enqueue_to(queue_from_class(klass), klass, *args) + end + + # Just like `enqueue` but allows you to specify the queue you want to + # use. Runs hooks. + # + # `queue` should be the String name of the queue you're targeting. + # + # Returns true if the job was queued, nil if the job was rejected by a + # before_enqueue hook. + # + # This method is considered part of the `stable` API. + def enqueue_to(queue, klass, *args) # Perform before_enqueue hooks. Don't perform enqueue if any hook returns false before_hooks = Plugin.before_enqueue_hooks(klass).collect do |hook| klass.send(hook, *args) end return nil if before_hooks.any? { |result| result == false } - Job.create(queue_from_class(klass), klass, *args) + Job.create(queue, klass, *args) Plugin.after_enqueue_hooks(klass).each do |hook| klass.send(hook, *args)