Skip to content

Commit

Permalink
Fixing Queue Now when 'queue' is provided in schedule, storing 'queue…
Browse files Browse the repository at this point in the history
…' in delayed queue so scheduler doesn't have to load classes, fixing bugs
  • Loading branch information
Ben VandenBos committed Mar 1, 2010
1 parent 1d6d79f commit a8a16ad
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
9 changes: 9 additions & 0 deletions HISTORY.md
@@ -1,3 +1,12 @@
## 1.0.5 (2010-03-01)

* Fixed support for overriding queue from schedule config.
* Removed resque-web dependency on loading the job classes for "Queue Now",
provided "queue" is specified in the schedule.
* The queue is now stored with the job and arguments in the delayed queue so
there is no longer a need for the scheduler to load job classes to introspect
the queue.

## 1.0.4 (2010-02-26)

* Added support for specifying the queue to put the job onto. This allows for
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -37,7 +37,7 @@ queue is given it is not necessary for the scheduler to load the class.
clear_leaderboards_moderator:
cron: "30 6 * * 1"
class: ClearLeaderboards
queue: scoring
queue: scoring
args: moderators
description: "This job resets the weekly leaderboard for moderators"

Expand Down
4 changes: 2 additions & 2 deletions lib/resque/scheduler.rb
Expand Up @@ -71,8 +71,8 @@ def handle_delayed_items
handle_shutdown do
if item = Resque.next_item_for_timestamp(timestamp)
log "queuing #{item['class']} [delayed]"
klass = constantize(item['class'])
Resque.enqueue(klass, *item['args'])
queue = item['queue'] || queue_from_class(constantize(item['class']))
Job.create(queue, item['class'], *item['args'])
end
end
# continue processing until there are no more ready items in this timestamp
Expand Down
2 changes: 1 addition & 1 deletion lib/resque_scheduler.rb
Expand Up @@ -38,7 +38,7 @@ def schedule
# for queueing. Until timestamp is in the past, the job will
# sit in the schedule list.
def enqueue_at(timestamp, klass, *args)
delayed_push(timestamp, :class => klass.to_s, :args => args)
delayed_push(timestamp, :class => klass.to_s, :args => args, :queue => queue_from_class(klass))
end

# Identical to enqueue_at but takes number_of_seconds_from_now
Expand Down
2 changes: 1 addition & 1 deletion lib/resque_scheduler/version.rb
@@ -1,3 +1,3 @@
module ResqueScheduler
Version = '1.0.4'
Version = '1.0.5'
end
7 changes: 5 additions & 2 deletions test/delayed_queue_test.rb
Expand Up @@ -98,7 +98,7 @@ def test_delayed_timestamp_peek
assert_equal(1, Resque.delayed_timestamp_peek(t, 0, 1).length)
assert_equal(2, Resque.delayed_timestamp_peek(t, 0, 3).length)

assert_equal({'args' => [], 'class' => 'SomeIvarJob'}, Resque.delayed_timestamp_peek(t, 0, 1).first)
assert_equal({'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar'}, Resque.delayed_timestamp_peek(t, 0, 1).first)
end

def test_handle_delayed_items_with_no_items
Expand All @@ -110,7 +110,10 @@ def test_handle_delayed_items_with_items
t = Time.now - 60 # in the past
Resque.enqueue_at(t, SomeIvarJob)
Resque.enqueue_at(t, SomeIvarJob)
Resque.expects(:enqueue).twice

# 2 SomeIvarJob jobs should be created in the "ivar" queue
Resque::Job.expects(:create).twice.with('ivar', 'SomeIvarJob')
Resque::Scheduler.expects(:queue_from_class).never # Should NOT need to load the class
Resque::Scheduler.handle_delayed_items
end

Expand Down

0 comments on commit a8a16ad

Please sign in to comment.