Skip to content

Commit e395825

Browse files
author
Nicolas Fouché
committed
Merge remote-tracking branch 'defunkt/master'
Conflicts: .gitignore bin/resque deps.rip lib/resque.rb lib/resque/failure/redis.rb lib/resque/server/public/ranger.js lib/resque/worker.rb resque-mongo.gemspec test/job_hooks_test.rb test/job_plugins_test.rb test/plugin_test.rb test/resque-web_test.rb test/resque_test.rb test/worker_test.rb
2 parents 9ae8ad6 + b569484 commit e395825

38 files changed

+433
-181
lines changed

Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source :rubygems
2+
3+
gemspec
4+
5+
group :test do
6+
gem "rack-test", "~> 0.5"
7+
end

Gemfile.lock

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
PATH
2+
remote: .
3+
specs:
4+
resque (1.13.0)
5+
json (~> 1.4.6)
6+
redis-namespace (>= 0.10.0)
7+
sinatra (>= 0.9.2)
8+
vegas (~> 0.1.2)
9+
10+
GEM
11+
remote: http://rubygems.org/
12+
specs:
13+
json (1.4.6)
14+
rack (1.2.2)
15+
rack-test (0.5.7)
16+
rack (>= 1.0)
17+
redis (2.1.1)
18+
redis-namespace (0.10.0)
19+
redis (< 3.0.0)
20+
sinatra (1.2.1)
21+
rack (~> 1.1)
22+
tilt (>= 1.2.2, < 2.0)
23+
tilt (1.2.2)
24+
vegas (0.1.8)
25+
rack (>= 1.0.0)
26+
27+
PLATFORMS
28+
ruby
29+
30+
DEPENDENCIES
31+
rack-test (~> 0.5)
32+
resque!

HISTORY.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
## 1.15.0 (2011-03-18)
2+
3+
* Fallback to Redis.connect. Makes ENV variables and whatnot work.
4+
* Fixed Sinatra 1.2 compatibility
5+
6+
## 1.14.0 (2011-03-17)
7+
8+
* Sleep interval can now be a float
9+
* Added Resque.inline to allow in-process performing of jobs (for testing)
10+
* Fixed tests for Ruby 1.9.2
11+
* Added Resque.validate(klass) to validate a Job
12+
* Decode errors are no longer ignored to help debugging
13+
* Web: Sinatra 1.2 compatibility
14+
* Fixed after_enqueue hook to actually run in `Resque.enqueue`
15+
* Fixed very_verbose timestamps to use 24 hour time (AM/PM wasn't included)
16+
* Fixed monit example
17+
* Fixed Worker#pid
18+
19+
## 1.13.0 (2011-02-07)
20+
21+
* Depend on redis-namespace >= 0.10
22+
* README tweaks
23+
* Use thread_safe option when setting redis url
24+
* Bugfix: worker pruning
25+
26+
## 1.12.0 (2011-02-03)
27+
28+
* Added pidfile writing from `rake resque:work`
29+
* Added Worker#pid method
30+
* Added configurable location for `rake install`
31+
* Bugfix: Errors in failure backend are rescue'd
32+
* Bugfix: Non-working workers no longer counted in "working" count
33+
* Bugfix: Don't think resque-web is a worker
34+
135
## 1.11.0 (2010-08-23)
236

337
* Web UI: Group /workers page by hostnames

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2009 Chris Wanstrath
1+
Copyright (c) Chris Wanstrath
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.markdown

+19-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Also, check your mongo version: 1.3.0 or higher
2121
Resque
2222
======
2323

24-
Resque is a Redis-backed library for creating background jobs, placing
25-
those jobs on multiple queues, and processing them later.
24+
Resque (pronounced like "rescue") is a Redis-backed library for creating
25+
background jobs, placing those jobs on multiple queues, and processing
26+
them later.
2627

2728
Background jobs can be any Ruby class or module that responds to
2829
`perform`. Your existing classes can easily be converted to background
@@ -254,6 +255,13 @@ variable.
254255

255256
$ VVERBOSE=1 QUEUE=file_serve rake environment resque:work
256257

258+
### Process IDs (PIDs)
259+
260+
There are scenarios where it's helpful to record the PID of a resque
261+
worker process. Use the PIDFILE option for easy access to the PID:
262+
263+
$ PIDFILE=./resque.pid QUEUE=file_serve rake environment resque:work
264+
257265

258266
### Priorities and Queue Lists
259267

@@ -439,7 +447,8 @@ You can also set the namespace directly using `resque-web`:
439447
Using Passenger? Resque ships with a `config.ru` you can use. See
440448
Phusion's guide:
441449

442-
<http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application>
450+
Apache: <http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_rack_based_ruby_application>
451+
Nginx: <http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_rack_app>
443452

444453
### Rack::URLMap
445454

@@ -546,7 +555,7 @@ together. But, it's not that hard.
546555
Resque Dependencies
547556
-------------------
548557

549-
gem install redis redis-namespace yajl-ruby
558+
gem install redis redis-namespace yajl-ruby vegas sinatra
550559

551560
If you cannot install `yajl-ruby` (JRuby?), you can install the `json`
552561
gem and Resque will use it instead.
@@ -673,6 +682,11 @@ this way we can tell our Sinatra app about the config file:
673682

674683
Now everyone is on the same page.
675684

685+
Also, you could disable jobs queueing by setting 'inline' attribute.
686+
For example, if you want to run all jobs in the same process for cucumber, try:
687+
688+
Resque.inline = ENV['RAILS_ENV'] == "cucumber"
689+
676690

677691
Plugins and Hooks
678692
-----------------
@@ -770,7 +784,7 @@ Once you've made your great commits:
770784
1. [Fork][1] Resque
771785
2. Create a topic branch - `git checkout -b my_branch`
772786
3. Push to your branch - `git push origin my_branch`
773-
4. Create an [Issue][2] with a link to your branch
787+
4. Create a [Pull Request](http://help.github.com/pull-requests/) from your branch
774788
5. That's it!
775789

776790
You might want to checkout our [Contributing][cb] wiki page for information

Rakefile

+13-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ end
1212
# Tests
1313
#
1414

15+
require 'rake/testtask'
16+
1517
task :default => :test
1618

17-
desc "Run the test suite"
18-
task :test do
19-
rg = command?(:rg)
20-
Dir['test/**/*_test.rb'].each do |f|
21-
rg ? sh("rg #{f}") : ruby(f)
19+
if command?(:rg)
20+
desc "Run the test suite with rg"
21+
task :test do
22+
Dir['test/**/*_test.rb'].each do |f|
23+
sh("rg #{f}")
24+
end
2225
end
26+
else
27+
Rake::TestTask.new do |test|
28+
test.libs << "test"
29+
test.test_files = FileList['test/**/*_test.rb']
30+
end
2331
end
2432

2533
if command? :kicker

bin/resque

+30-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
#!/usr/bin/env ruby
22

3-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
44
require 'resque'
5+
require 'optparse'
6+
7+
parser = OptionParser.new do |opts|
8+
opts.banner = "Usage: resque [options] COMMAND"
9+
10+
opts.separator ""
11+
opts.separator "Options:"
12+
13+
opts.on("-m", "--mongo [HOST:PORT]", "Redis connection string") do |host|
14+
Resque.mongo = host
15+
end
16+
17+
opts.on("-N", "--namespace [NAMESPACE]", "Redis namespace") do |namespace|
18+
Resque.redis.namespace = namespace
19+
end
20+
21+
opts.on("-h", "--help", "Show this message") do
22+
puts opts
23+
exit
24+
end
25+
26+
opts.separator ""
27+
opts.separator "Commands:"
28+
opts.separator " remove WORKER Removes a worker"
29+
opts.separator " kill WORKER Kills a worker"
30+
opts.separator " list Lists known workers"
31+
end
532

633
def kill(worker)
734
abort "** resque kill WORKER_ID" if worker.nil?
@@ -34,11 +61,7 @@ def list
3461
end
3562
end
3663

37-
if (i = ARGV.index('-r')) && ARGV[i+1]
38-
Resque.mongo = ARGV[i+1]
39-
ARGV.delete_at(i)
40-
ARGV.delete_at(i+1)
41-
end
64+
parser.parse!
4265

4366
case ARGV[0]
4467
when 'kill'
@@ -48,10 +71,5 @@ when 'remove'
4871
when 'list'
4972
list
5073
else
51-
puts "Usage: resque [-r mongo_host:mongo_port] COMMAND [option]"
52-
puts
53-
puts "Commands:"
54-
puts " remove WORKER Removes a worker"
55-
puts " kill WORKER Kills a worker"
56-
puts " list Lists known workers"
74+
puts parser.help
5775
end

deps.rip

-8
This file was deleted.

examples/demo/README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Great, now let's check out the Resque frontend. Either click on 'View
5454
Resque' in your web browser or run:
5555

5656
$ open http://localhost:9292/resque/
57-
57+
5858
You should see the Resque web frontend. 404 page? Don't forget the
5959
trailing slash!
6060

examples/monit/resque.monit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
check process resque_worker_QUEUE
22
with pidfile /data/APP_NAME/current/tmp/pids/resque_worker_QUEUE.pid
3-
start program = "/bin/sh -c 'cd /data/APP_NAME/current; RAILS_ENV=production QUEUE=queue_name VERBOSE=1 nohup rake environment resque:work& > log/resque_worker_QUEUE.log && echo $! > tmp/pids/resque_worker_QUEUE.pid'" as uid deploy and gid deploy
3+
start program = "/bin/sh -c 'cd /data/APP_NAME/current; nohup rake environment resque:work RAILS_ENV=production QUEUE=queue_name VERBOSE=1 PIDFILE=tmp/pids/resque_worker_QUEUE.pid & > log/resque_worker_QUEUE.log" as uid deploy and gid deploy
44
stop program = "/bin/sh -c 'cd /data/APP_NAME/current && kill -s QUIT `cat tmp/pids/resque_worker_QUEUE.pid` && rm -f tmp/pids/resque_worker_QUEUE.pid; exit 0;'"
55
if totalmem is greater than 300 MB for 10 cycles then restart # eating up memory?
66
group resque_workers

lib/resque.rb

+34
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def to_s
145145
"Resque Client connected to #{@con.primary[0]}:#{@con.primary[1]}/#{@db.name}/#{@mongo.name}"
146146
end
147147

148+
148149
def add_indexes
149150
@mongo.create_index([[:queue,1],[:date, 1]])
150151
@mongo.create_index :queue
@@ -154,6 +155,18 @@ def add_indexes
154155
@failures.create_index :queue
155156
end
156157

158+
# If 'inline' is true Resque will call #perform method inline
159+
# without queuing it into Redis and without any Resque callbacks.
160+
# The 'inline' is false Resque jobs will be put in queue regularly.
161+
def inline?
162+
@inline
163+
end
164+
alias_method :inline, :inline?
165+
166+
def inline=(inline)
167+
@inline = inline
168+
end
169+
157170
#
158171
# queue manipulation
159172
#
@@ -247,6 +260,10 @@ def watch_queue(queue)
247260
# This method is considered part of the `stable` API.
248261
def enqueue(klass, *args)
249262
Job.create(queue_from_class(klass), klass, *args)
263+
264+
Plugin.after_enqueue_hooks(klass).each do |hook|
265+
klass.send(hook, *args)
266+
end
250267
end
251268

252269
# This method can be used to conveniently remove a job from a queue.
@@ -296,6 +313,23 @@ def reserve(queue)
296313
Job.reserve(queue)
297314
end
298315

316+
# Validates if the given klass could be a valid Resque job
317+
#
318+
# If no queue can be inferred this method will raise a `Resque::NoQueueError`
319+
#
320+
# If given klass is nil this method will raise a `Resque::NoClassError`
321+
def validate(klass, queue = nil)
322+
queue ||= queue_from_class(klass)
323+
324+
if !queue
325+
raise NoQueueError.new("Jobs must be placed onto a queue.")
326+
end
327+
328+
if klass.to_s.empty?
329+
raise NoClassError.new("Jobs must be given a class.")
330+
end
331+
end
332+
299333

300334
#
301335
# worker shortcuts

lib/resque/errors.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class NoQueueError < RuntimeError; end
44

55
# Raised when trying to create a job without a class
66
class NoClassError < RuntimeError; end
7-
7+
88
# Raised when a worker was killed while processing a job.
99
class DirtyExit < RuntimeError; end
1010
end

lib/resque/failure.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ def self.search_results(start = 0, count = 1, squery)
6565
def self.url
6666
backend.url
6767
end
68-
68+
6969
# Clear all failure jobs
7070
def self.clear
7171
backend.clear
7272
end
73-
73+
7474
def self.requeue(index)
7575
backend.requeue(index)
7676
end
77+
78+
def self.remove(index)
79+
backend.remove(index)
80+
end
7781
end
7882
end

lib/resque/failure/base.rb

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def self.clear
6262
def self.requeue(index)
6363
end
6464

65+
def self.remove(index)
66+
end
67+
6568
# Logging!
6669
def log(message)
6770
@worker.log(message)

0 commit comments

Comments
 (0)