resque-scheduler 1.9.5 → 1.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +6 -1
- data/README.markdown +38 -0
- data/Rakefile +2 -2
- data/lib/resque/scheduler.rb +14 -2
- data/lib/resque_scheduler/version.rb +1 -1
- data/resque-scheduler.gemspec +2 -2
- data/test/scheduler_test.rb +9 -0
- metadata +4 -4
data/HISTORY.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
## 1.9.
|
|
1
|
+
## 1.9.6 (2010-10-08)
|
|
2
|
+
|
|
3
|
+
* Support for custom job classes (like resque-status) (mattetti)
|
|
4
|
+
|
|
5
|
+
## 1.9.5 (2010-09-09)
|
|
2
6
|
|
|
3
7
|
* Updated scheduler rake task to allow for an alternate setup task
|
|
4
8
|
to avoid loading the entire stack. (chewbranca)
|
|
9
|
+
* Fixed sig issue on win32 (#25)
|
|
5
10
|
|
|
6
11
|
## 1.9.4 (2010-07-29)
|
|
7
12
|
|
data/README.markdown
CHANGED
|
@@ -138,6 +138,40 @@ Multiple envs are allowed, separated by commas:
|
|
|
138
138
|
NOTE: If you specify the `rails_env` arg without setting RAILS_ENV as an
|
|
139
139
|
environment variable, the job won't be loaded.
|
|
140
140
|
|
|
141
|
+
### Support for customized Job classes
|
|
142
|
+
|
|
143
|
+
Some Resque extensions like [resque-status](http://github.com/quirkey/resque-status) use custom job classes with a slightly different API signature.
|
|
144
|
+
Resque-scheduler isn't trying to support all existing and future custom job classes, instead it supports a schedule flag so you can extend your custom class
|
|
145
|
+
and make it support scheduled job.
|
|
146
|
+
|
|
147
|
+
Let's pretend we have a JobWithStatus class called FakeLeaderboard
|
|
148
|
+
|
|
149
|
+
class FakeLeaderboard < Resque::JobWithStatus
|
|
150
|
+
def perfom
|
|
151
|
+
# do something and keep track of the status
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
create_fake_leaderboards:
|
|
156
|
+
cron: "30 6 * * 1"
|
|
157
|
+
queue: scoring
|
|
158
|
+
custom_job_class: FakeLeaderboard
|
|
159
|
+
args:
|
|
160
|
+
rails_env: demo
|
|
161
|
+
description: "This job will auto-create leaderboards for our online demo and the status will update as the worker makes progress"
|
|
162
|
+
|
|
163
|
+
If your extension doesn't support scheduled job, you would need to extend the custom job class to support the #scheduled method:
|
|
164
|
+
|
|
165
|
+
module Resque
|
|
166
|
+
class JobWithStatus
|
|
167
|
+
# Wrapper API to forward a Resque::Job creation API call into a JobWithStatus call.
|
|
168
|
+
def self.scheduled(queue, klass, *args)
|
|
169
|
+
create(args)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
|
|
141
175
|
Resque-web additions
|
|
142
176
|
--------------------
|
|
143
177
|
|
|
@@ -199,6 +233,10 @@ any nonempty value, they will take effect. `VERBOSE` simply dumps more output
|
|
|
199
233
|
to stdout. `MUTE` does the opposite and silences all output. `MUTE` supercedes
|
|
200
234
|
`VERBOSE`.
|
|
201
235
|
|
|
236
|
+
NOTE: You DO NOT want to run >1 instance of the scheduler. Doing so will result
|
|
237
|
+
in the same job being queued more than once. You only need one instnace of the
|
|
238
|
+
scheduler running per resque instance (regardless of number of machines).
|
|
239
|
+
|
|
202
240
|
|
|
203
241
|
Plagurism alert
|
|
204
242
|
---------------
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
load 'tasks/resque_scheduler.rake'
|
|
1
|
+
load File.expand_path('tasks/resque_scheduler.rake')
|
|
2
2
|
|
|
3
3
|
$LOAD_PATH.unshift 'lib'
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ task :default => :test
|
|
|
7
7
|
desc "Run tests"
|
|
8
8
|
task :test do
|
|
9
9
|
Dir['test/*_test.rb'].each do |f|
|
|
10
|
-
require f
|
|
10
|
+
require File.expand_path(f)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
data/lib/resque/scheduler.rb
CHANGED
|
@@ -97,7 +97,13 @@ module Resque
|
|
|
97
97
|
if item = Resque.next_item_for_timestamp(timestamp)
|
|
98
98
|
log "queuing #{item['class']} [delayed]"
|
|
99
99
|
queue = item['queue'] || Resque.queue_from_class(constantize(item['class']))
|
|
100
|
-
|
|
100
|
+
# Support custom job classes like job with status
|
|
101
|
+
if (job_klass = item['custom_job_class']) && (job_klass != 'Resque::Job')
|
|
102
|
+
# custom job classes not supporting the same API calls must implement the #schedule method
|
|
103
|
+
constantize(job_klass).scheduled(queue, item['class'], *item['args'])
|
|
104
|
+
else
|
|
105
|
+
Resque::Job.create(queue, item['class'], *item['args'])
|
|
106
|
+
end
|
|
101
107
|
end
|
|
102
108
|
end
|
|
103
109
|
# continue processing until there are no more ready items in this timestamp
|
|
@@ -116,7 +122,13 @@ module Resque
|
|
|
116
122
|
klass_name = config['class'] || config[:class]
|
|
117
123
|
params = args.nil? ? [] : Array(args)
|
|
118
124
|
queue = config['queue'] || config[:queue] || Resque.queue_from_class(constantize(klass_name))
|
|
119
|
-
|
|
125
|
+
# Support custom job classes like job with status
|
|
126
|
+
if (job_klass = config['custom_job_class']) && (job_klass != 'Resque::Job')
|
|
127
|
+
# custom job classes not supporting the same API calls must implement the #schedule method
|
|
128
|
+
constantize(job_klass).scheduled(queue, klass_name, *params)
|
|
129
|
+
else
|
|
130
|
+
Resque::Job.create(queue, klass_name, *params)
|
|
131
|
+
end
|
|
120
132
|
end
|
|
121
133
|
|
|
122
134
|
def rufus_scheduler
|
data/resque-scheduler.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{resque-scheduler}
|
|
8
|
-
s.version = "1.9.
|
|
8
|
+
s.version = "1.9.6"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Ben VandenBos"]
|
|
12
|
-
s.date = %q{2010-
|
|
12
|
+
s.date = %q{2010-10-08}
|
|
13
13
|
s.description = %q{Light weight job scheduling on top of Resque.
|
|
14
14
|
Adds methods enqueue_at/enqueue_in to schedule jobs in the future.
|
|
15
15
|
Also supports queueing jobs on a fixed, cron-like schedule.}
|
data/test/scheduler_test.rb
CHANGED
|
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
|
2
2
|
|
|
3
3
|
class Resque::SchedulerTest < Test::Unit::TestCase
|
|
4
4
|
|
|
5
|
+
class FakeJob
|
|
6
|
+
def self.scheduled(queue, klass, *args); end
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
def setup
|
|
6
10
|
Resque::Scheduler.clear_schedule!
|
|
7
11
|
end
|
|
@@ -15,6 +19,11 @@ class Resque::SchedulerTest < Test::Unit::TestCase
|
|
|
15
19
|
Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
|
|
16
20
|
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
|
|
17
21
|
end
|
|
22
|
+
|
|
23
|
+
def test_enqueue_from_config_with_custom_class_job_in_the_resque_queue
|
|
24
|
+
FakeJob.stubs(:scheduled).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
|
|
25
|
+
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'custom_job_class' => 'Resque::SchedulerTest::FakeJob', 'args' => "/tmp")
|
|
26
|
+
end
|
|
18
27
|
|
|
19
28
|
def test_enqueue_from_config_puts_stuff_in_the_resque_queue_when_env_match
|
|
20
29
|
# The job should be loaded : its rails_env config matches the RAILS_ENV variable:
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resque-scheduler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 63
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 9
|
|
9
|
-
-
|
|
10
|
-
version: 1.9.
|
|
9
|
+
- 6
|
|
10
|
+
version: 1.9.6
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Ben VandenBos
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-10-08 00:00:00 -07:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|