resque 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of resque might be problematic. Click here for more details.
- data/.gitignore +2 -0
- data/HISTORY.md +6 -0
- data/README.markdown +21 -13
- data/Rakefile +7 -4
- data/lib/resque.rb +8 -0
- data/lib/resque/job.rb +0 -1
- data/lib/resque/server/public/ranger.js +4 -1
- data/lib/resque/tasks.rb +4 -2
- data/lib/resque/version.rb +1 -1
- data/lib/resque/worker.rb +7 -2
- data/test/resque_test.rb +8 -0
- data/test/test_helper.rb +1 -1
- data/test/worker_test.rb +9 -0
- metadata +34 -4
data/.gitignore
ADDED
data/HISTORY.md
CHANGED
data/README.markdown
CHANGED
@@ -17,7 +17,7 @@ comprised of three parts:
|
|
17
17
|
3. A Sinatra app for monitoring queues, jobs, and workers.
|
18
18
|
|
19
19
|
Resque workers can be distributed between multiple machines,
|
20
|
-
support priorities, are
|
20
|
+
support priorities, are resilient to memory bloat / "leaks," are
|
21
21
|
optimized for REE (but work on MRI and JRuby), tell you what they're
|
22
22
|
doing, and expect failure.
|
23
23
|
|
@@ -151,12 +151,12 @@ do this:
|
|
151
151
|
This is why our above example (and all the examples in `examples/`)
|
152
152
|
uses object IDs instead of passing around the objects.
|
153
153
|
|
154
|
-
While this is less convenient than just sticking a
|
154
|
+
While this is less convenient than just sticking a marshaled object
|
155
155
|
in the database, it gives you a slight advantage: your jobs will be
|
156
156
|
run against the most recent version of an object because they need to
|
157
157
|
pull from the DB or cache.
|
158
158
|
|
159
|
-
If your jobs were run against
|
159
|
+
If your jobs were run against marshaled objects, they could
|
160
160
|
potentially be operating on a stale record with out-of-date information.
|
161
161
|
|
162
162
|
|
@@ -184,7 +184,7 @@ exceptions you would not normally throw in order to assist debugging.
|
|
184
184
|
Workers
|
185
185
|
-------
|
186
186
|
|
187
|
-
Resque workers are rake tasks
|
187
|
+
Resque workers are rake tasks that run forever. They basically do this:
|
188
188
|
|
189
189
|
start
|
190
190
|
loop do
|
@@ -225,7 +225,7 @@ We don't want the `git_timeout` as high as 10 minutes in our web app,
|
|
225
225
|
but in the Resque workers it's fine.
|
226
226
|
|
227
227
|
|
228
|
-
|
228
|
+
### Logging
|
229
229
|
|
230
230
|
Workers support basic logging to STDOUT. If you start them with the
|
231
231
|
`VERBOSE` env variable set, they will print basic debugging
|
@@ -354,10 +354,17 @@ Resque workers respond to a few different signals:
|
|
354
354
|
If you want to gracefully shutdown a Resque worker, use `QUIT`.
|
355
355
|
|
356
356
|
If you want to kill a stale or stuck child, use `USR1`. Processing
|
357
|
-
will continue as normal.
|
357
|
+
will continue as normal unless the child was not found. In that case
|
358
|
+
Resque assumes the parent process is in a bad state and shuts down.
|
358
359
|
|
359
360
|
If you want to kill a stale or stuck child and shutdown, use `TERM`
|
360
361
|
|
362
|
+
### Mysql::Error: MySQL server has gone away
|
363
|
+
|
364
|
+
If your workers remain idle for too long they may lose their MySQL
|
365
|
+
connection. If that happens we recommend using [this
|
366
|
+
Gist](http://gist.github.com/238999).
|
367
|
+
|
361
368
|
|
362
369
|
The Front End
|
363
370
|
-------------
|
@@ -367,7 +374,7 @@ your queue.
|
|
367
374
|
|
368
375
|
![The Front End](http://img.skitch.com/20091104-tqh5pgkwgbskjbk7qbtmpesnyw.jpg)
|
369
376
|
|
370
|
-
|
377
|
+
### Standalone
|
371
378
|
|
372
379
|
If you've installed Resque as a gem running the front end standalone is easy:
|
373
380
|
|
@@ -419,7 +426,7 @@ over the other?
|
|
419
426
|
* Resque can only place JSONable Ruby objects on a queue as arguments
|
420
427
|
* DelayedJob can place _any_ Ruby object on its queue as arguments
|
421
428
|
* Resque includes a Sinatra app for monitoring what's going on
|
422
|
-
* DelayedJob can be
|
429
|
+
* DelayedJob can be queried from within your Rails app if you want to
|
423
430
|
add an interface
|
424
431
|
|
425
432
|
If you're doing Rails development, you already have a database and
|
@@ -643,7 +650,7 @@ correctly (though we make an effort to tell you if we feel this is the
|
|
643
650
|
case). The tests attempt to start an isolated instance of Redis to
|
644
651
|
run against.
|
645
652
|
|
646
|
-
Also make sure you've installed all the
|
653
|
+
Also make sure you've installed all the dependencies correctly. For
|
647
654
|
example, try loading the `redis-namespace` gem after you've installed
|
648
655
|
it:
|
649
656
|
|
@@ -665,10 +672,10 @@ Contributing
|
|
665
672
|
|
666
673
|
Once you've made your great commits:
|
667
674
|
|
668
|
-
1. [Fork]
|
675
|
+
1. [Fork][1] Resque
|
669
676
|
2. Create a topic branch - `git checkout -b my_branch`
|
670
677
|
3. Push to your branch - `git push origin my_branch`
|
671
|
-
4. Create an [Issue]
|
678
|
+
4. Create an [Issue][2] with a link to your branch
|
672
679
|
5. That's it!
|
673
680
|
|
674
681
|
|
@@ -690,6 +697,7 @@ Meta
|
|
690
697
|
* Docs: <http://defunkt.github.com/resque/>
|
691
698
|
* Bugs: <http://github.com/defunkt/resque/issues>
|
692
699
|
* List: <resque@librelist.com>
|
700
|
+
* Chat: <irc://irc.freenode.net/resque>
|
693
701
|
* Gems: <http://gemcutter.org/gems/resque>
|
694
702
|
|
695
703
|
|
@@ -699,5 +707,5 @@ Author
|
|
699
707
|
Chris Wanstrath :: chris@ozmm.org :: @defunkt
|
700
708
|
|
701
709
|
[0]: http://github.com/blog/542-introducing-resque
|
702
|
-
[
|
703
|
-
[
|
710
|
+
[1]: http://help.github.com/forking/
|
711
|
+
[2]: http://github.com/defunkt/resque/issues
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
load 'tasks/redis.rake'
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift
|
3
|
+
$LOAD_PATH.unshift 'lib'
|
4
4
|
require 'resque/tasks'
|
5
5
|
|
6
6
|
task :default => :test
|
@@ -27,7 +27,6 @@ task :gem => [ :test, :gemspec, :build ]
|
|
27
27
|
|
28
28
|
begin
|
29
29
|
require 'jeweler'
|
30
|
-
$LOAD_PATH.unshift 'lib'
|
31
30
|
require 'resque/version'
|
32
31
|
|
33
32
|
Jeweler::Tasks.new do |gemspec|
|
@@ -37,7 +36,11 @@ begin
|
|
37
36
|
gemspec.email = "chris@ozmm.org"
|
38
37
|
gemspec.homepage = "http://github.com/defunkt/resque"
|
39
38
|
gemspec.authors = ["Chris Wanstrath"]
|
40
|
-
gemspec.version = Resque::Version
|
39
|
+
gemspec.version = Resque::Version
|
40
|
+
|
41
|
+
gemspec.add_dependency "redis"
|
42
|
+
gemspec.add_dependency "redis-namespace"
|
43
|
+
gemspec.add_development_dependency "jeweler"
|
41
44
|
end
|
42
45
|
rescue LoadError
|
43
46
|
puts "Jeweler not available. Install it with: "
|
data/lib/resque.rb
CHANGED
@@ -100,6 +100,14 @@ module Resque
|
|
100
100
|
redis.smembers(:queues)
|
101
101
|
end
|
102
102
|
|
103
|
+
# Given a queue name, completely deletes the queue.
|
104
|
+
def remove_queue(queue)
|
105
|
+
@watched_queues ||= {}
|
106
|
+
@watched_queues.delete(queue.to_s)
|
107
|
+
redis.srem(:queues, queue.to_s)
|
108
|
+
redis.del("queue:#{queue}")
|
109
|
+
end
|
110
|
+
|
103
111
|
# Used internally to keep track of which queues we've created.
|
104
112
|
# Don't call this directly.
|
105
113
|
def watch_queue(queue)
|
data/lib/resque/job.rb
CHANGED
@@ -58,7 +58,6 @@ module Resque
|
|
58
58
|
# Calls #perform on the class given in the payload with the
|
59
59
|
# arguments given in the payload.
|
60
60
|
def perform
|
61
|
-
return unless payload_class && payload_class.respond_to?(:perform)
|
62
61
|
args ? payload_class.perform(*args) : payload_class.perform
|
63
62
|
end
|
64
63
|
|
@@ -1,4 +1,7 @@
|
|
1
|
+
var poll_interval = 2;
|
2
|
+
|
1
3
|
$(function() {
|
4
|
+
|
2
5
|
$('.time').relatizeDate()
|
3
6
|
$('.backtrace').click(function() {
|
4
7
|
$(this).next().toggle()
|
@@ -14,7 +17,7 @@ $(function() {
|
|
14
17
|
$('#main').html(data)
|
15
18
|
$('#main .time').relatizeDate()
|
16
19
|
}})
|
17
|
-
},
|
20
|
+
}, poll_interval * 1000)
|
18
21
|
return false
|
19
22
|
})
|
20
23
|
|
data/lib/resque/tasks.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
# will give you the resque tasks
|
3
3
|
|
4
4
|
namespace :resque do
|
5
|
+
task :setup
|
6
|
+
|
5
7
|
desc "Start a Resque Ranger"
|
6
|
-
task :work do
|
7
|
-
|
8
|
+
task :work => :setup do
|
9
|
+
require 'resque'
|
8
10
|
|
9
11
|
worker = nil
|
10
12
|
queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
|
data/lib/resque/version.rb
CHANGED
data/lib/resque/worker.rb
CHANGED
@@ -245,7 +245,12 @@ module Resque
|
|
245
245
|
def kill_child
|
246
246
|
if @child
|
247
247
|
log! "Killing child at #{@child}"
|
248
|
-
|
248
|
+
if system("ps -ho pid,state -p #{@child}")
|
249
|
+
Process.kill("KILL", @child) rescue nil
|
250
|
+
else
|
251
|
+
log! "Child #{@child} not found, restarting."
|
252
|
+
shutdown
|
253
|
+
end
|
249
254
|
end
|
250
255
|
end
|
251
256
|
|
@@ -383,7 +388,7 @@ module Resque
|
|
383
388
|
# Returns an array of string pids of all the other workers on this
|
384
389
|
# machine. Useful when pruning dead workers on startup.
|
385
390
|
def worker_pids
|
386
|
-
`ps -
|
391
|
+
`ps -A -o pid,command | grep [r]esque`.split("\n").map do |line|
|
387
392
|
line.split(' ')[0]
|
388
393
|
end
|
389
394
|
end
|
data/test/resque_test.rb
CHANGED
@@ -118,6 +118,14 @@ context "Resque" do
|
|
118
118
|
assert_equal [], Resque.queues
|
119
119
|
end
|
120
120
|
|
121
|
+
test "can delete a queue" do
|
122
|
+
Resque.push(:cars, { 'make' => 'bmw' })
|
123
|
+
assert_equal %w( cars people ), Resque.queues
|
124
|
+
Resque.remove_queue(:people)
|
125
|
+
assert_equal %w( cars ), Resque.queues
|
126
|
+
assert_equal nil, Resque.pop(:people)
|
127
|
+
end
|
128
|
+
|
121
129
|
test "keeps track of resque keys" do
|
122
130
|
assert_equal ["queue:people", "queues"], Resque.keys
|
123
131
|
end
|
data/test/test_helper.rb
CHANGED
data/test/worker_test.rb
CHANGED
@@ -91,6 +91,15 @@ context "Resque::Worker" do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
test "fails if a job class has no `perform` method" do
|
95
|
+
worker = Resque::Worker.new(:perform_less)
|
96
|
+
Resque::Job.create(:perform_less, Object)
|
97
|
+
|
98
|
+
assert_equal 0, Resque::Failure.count
|
99
|
+
worker.work(0)
|
100
|
+
assert_equal 1, Resque::Failure.count
|
101
|
+
end
|
102
|
+
|
94
103
|
test "inserts itself into the 'workers' list on startup" do
|
95
104
|
@worker.work(0) do
|
96
105
|
assert_equal @worker, Resque.workers[0]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -9,10 +9,39 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-25 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redis
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redis-namespace
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jeweler
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
16
45
|
description: ""
|
17
46
|
email: chris@ozmm.org
|
18
47
|
executables:
|
@@ -24,6 +53,7 @@ extra_rdoc_files:
|
|
24
53
|
- LICENSE
|
25
54
|
- README.markdown
|
26
55
|
files:
|
56
|
+
- .gitignore
|
27
57
|
- .kick
|
28
58
|
- HISTORY.md
|
29
59
|
- LICENSE
|