Skip to content

Commit

Permalink
Now able to add Jobs to a Queue from the Schedule without having the …
Browse files Browse the repository at this point in the history
…Job loaded in the process.
  • Loading branch information
malomalo authored and bvandenbos committed Feb 26, 2010
1 parent df72e6d commit 08c9e74
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.4 (2010-02-26)

* Added support for specifying the queue to put the job onto. This allows for
you to have one job that can go onto multiple queues and be able to schedule
jobs without having to load the job classes.

## 1.0.3 (2010-02-11)

* Added support for scheduled jobs with empty crons. This is helpful to have
Expand Down
15 changes: 10 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resque-scheduler
===============

Resque-scheduler is an extension to [Resque](http://github.com/defunkt/resque) that adds support for queueing items
in the future.
Resque-scheduler is an extension to [Resque](http://github.com/defunkt/resque)
that adds support for queueing items in the future.

Requires redis >=1.1.

Expand All @@ -22,17 +22,22 @@ is most likely stored in a YAML like so:
cron: "0 0 * * *"
class: QueueDocuments
args:
description: "This job queues all content for indexing in solr
description: "This job queues all content for indexing in solr"

clear_leaderboards_contributors:
cron: "30 6 * * 1"
class: ClearLeaderboards
args: contributors
description: "This job resets the weekly leaderboard for contributions"

A queue option can also be specified. When job will go onto the specified queue
if it is available (Even if @queue is specified in the job class). When the
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
args: moderators
description: "This job resets the weekly leaderboard for moderators"

Expand All @@ -47,8 +52,8 @@ it will NOT be ran later when the scheduler process is started back up. In that
sense, you can sort of think of the scheduler process as crond. Delayed jobs,
however, are different.

A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler) for handling the heavy lifting of the
actual scheduling engine.
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
for handling the heavy lifting of the actual scheduling engine.

### Delayed jobs

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ begin
gemspec.authors = ["Ben VandenBos"]
gemspec.version = ResqueScheduler::Version

gemspec.add_dependency "resque", ">= 1.3.0"
gemspec.add_dependency "resque", ">= 1.5.0"
gemspec.add_dependency "rufus-scheduler"
gemspec.add_development_dependency "jeweler"
gemspec.add_development_dependency "mocha"
Expand Down
3 changes: 2 additions & 1 deletion lib/resque/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def enqueue_from_config(config)
args = config['args'] || config[:args]
klass_name = config['class'] || config[:class]
params = args.nil? ? [] : Array(args)
Resque.enqueue(constantize(klass_name), *params)
queue = config['queue'] || Resque.queue_from_class(constantize(klass_name))
Resque::Job.create(queue, klass_name, *params)
end

def rufus_scheduler
Expand Down
1 change: 1 addition & 0 deletions lib/resque_scheduler/server/views/scheduler.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<td><%= h config['description'] %></td>
<td style="white-space:nowrap"><%= h config['cron'] %></td>
<td><%= h config['class'] %></td>
<td><%= h config['queue'] || Resque.queue_from_class(constantize(config['class'])) %></td>
<td><%= h config['args'].inspect %></td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion lib/resque_scheduler/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ResqueScheduler
Version = '1.0.3'
Version = '1.0.4'
end
7 changes: 6 additions & 1 deletion test/scheduler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ def setup
Resque::Scheduler.clear_schedule!
end

def test_enqueue_from_config_puts_stuff_in_the_resque_queue_without_class_loaded
Resque::Job.stubs(:create).once.returns(true).with('joes_queue', 'BigJoesJob', '/tmp')
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'BigJoesJob', 'args' => "/tmp", 'queue' => 'joes_queue')
end

def test_enqueue_from_config_puts_stuff_in_the_resque_queue
Resque.stubs(:enqueue).once.returns(true).with(SomeIvarJob, '/tmp')
Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
end

Expand Down

0 comments on commit 08c9e74

Please sign in to comment.