Skip to content

Commit b9cc2c7

Browse files
committed
Merge branch 'master' into 2.0
Conflicts: HISTORY.md
2 parents 7b2f561 + f0374eb commit b9cc2c7

File tree

10 files changed

+99
-63
lines changed

10 files changed

+99
-63
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
*.gemspec
21
pkg
32
nbproject

HISTORY.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
* Resque now uses Unix Epoch Timestamps exclusively.
44

5+
## 1.8.0 (2010-04-07)
6+
7+
* Jobs that never complete due to killed worker are now failed.
8+
* Worker "working" state is now maintained by the parent, not the child.
9+
* Stopped using deprecated redis.rb methods
10+
* `Worker.working` race condition fixed
11+
* `Worker#process` has been deprecated.
12+
* Monit example fixed
13+
* Redis::Client and Redis::Namespace can be passed to `Resque.redis=`
14+
515
## 1.7.1 (2010-04-02)
616

717
* Bugfix: Make job hook execution order consistent

Rakefile

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,12 @@ end
4242

4343
task :install => [ 'redis:install', 'dtach:install' ]
4444

45-
desc "Build a gem"
46-
task :gem => [ :test, :gemspec, :build ]
47-
4845
begin
49-
require 'jeweler'
50-
require 'resque/version'
51-
52-
Jeweler::Tasks.new do |gemspec|
53-
gemspec.name = "resque"
54-
gemspec.summary = "Resque is a Redis-backed queueing system."
55-
gemspec.email = "[email protected]"
56-
gemspec.homepage = "http://github.com/defunkt/resque"
57-
gemspec.authors = ["Chris Wanstrath"]
58-
gemspec.version = Resque::Version
59-
60-
gemspec.add_dependency "redis"
61-
gemspec.add_dependency "redis-namespace"
62-
gemspec.add_dependency "vegas", ">=0.1.2"
63-
gemspec.add_dependency "sinatra", ">=0.9.2"
64-
gemspec.add_development_dependency "jeweler"
65-
66-
gemspec.description = <<description
67-
Resque is a Redis-backed Ruby library for creating background jobs,
68-
placing those jobs on multiple queues, and processing them later.
69-
70-
Background jobs can be any Ruby class or module that responds to
71-
perform. Your existing classes can easily be converted to background
72-
jobs or you can create new classes specifically to do work. Or, you
73-
can do both.
74-
75-
Resque is heavily inspired by DelayedJob (which rocks) and is
76-
comprised of three parts:
77-
78-
* A Ruby library for creating, querying, and processing jobs
79-
* A Rake task for starting a worker which processes jobs
80-
* A Sinatra app for monitoring queues, jobs, and workers.
81-
description
82-
end
46+
require 'mg'
47+
MG.new("resque.gemspec")
8348
rescue LoadError
84-
puts "Jeweler not available. Install it with: "
85-
puts "gem install jeweler"
49+
warn "mg not available."
50+
warn "Install it with: gem i mg"
8651
end
8752

8853

@@ -102,11 +67,12 @@ end
10267
#
10368

10469
desc "Push a new version to Gemcutter"
105-
task :publish => [ :test, :gemspec, :build ] do
106-
system "git tag v#{Resque::Version}"
107-
system "git push origin v#{Resque::Version}"
108-
system "git push origin master"
109-
system "gem push pkg/resque-#{Resque::Version}.gem"
110-
system "git clean -fd"
70+
task :publish => "gem:publish" do
71+
require 'resque/version'
72+
73+
sh "git tag v#{Resque::Version}"
74+
sh "git push origin v#{Resque::Version}"
75+
sh "git push origin master"
76+
sh "git clean -fd"
11177
exec "rake pages"
11278
end

lib/resque.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ module Resque
2626
# Accepts:
2727
# 1. A 'hostname:port' string
2828
# 2. A 'hostname:port:db' string (to select the Redis db)
29-
# 3. An instance of `Redis`, `Redis::Client`, or `Redis::Namespace`.
29+
# 3. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
30+
# or `Redis::Namespace`.
3031
def redis=(server)
3132
case server
3233
when String
3334
host, port, db = server.split(':')
3435
redis = Redis.new(:host => host, :port => port,
3536
:thread_safe => true, :db => db)
3637
@redis = Redis::Namespace.new(:resque, :redis => redis)
37-
when Redis, Redis::Client
38+
when Redis, Redis::Client, Redis::DistRedis
3839
@redis = Redis::Namespace.new(:resque, :redis => server)
3940
when Redis::Namespace
4041
@redis = server

lib/resque/failure/multiple.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ module Failure
33
# A Failure backend that uses multiple backends
44
# delegates all queries to the first backend
55
class Multiple < Base
6-
6+
77
class << self
88
attr_accessor :classes
99
end
10-
10+
1111
def self.configure
1212
yield self
1313
Resque::Failure.backend = self
1414
end
15-
15+
1616
def initialize(*args)
1717
@backends = self.class.classes.map {|klass| klass.new(*args)}
1818
end
1919
def save
2020
@backends.each(&:save)
2121
end
22-
22+
2323
# The number of failures.
2424
def self.count
2525
classes.first.count
@@ -34,11 +34,15 @@ def self.all(start = 0, count = 1)
3434
def self.url
3535
classes.first.url
3636
end
37-
37+
3838
# Clear all failure objects
3939
def self.clear
4040
classes.first.clear
4141
end
42+
43+
def self.requeue(*args)
44+
classes.first.requeue(*args)
45+
end
4246
end
4347
end
4448
end

lib/resque/server/views/failed.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
<dd><code><%= job['exception'] %></code></dd>
3636
<dt>Error</dt>
3737
<dd class='error'>
38-
<a href="#" class="backtrace"><%= h(job['error']) %></a>
39-
<pre style='display:none'><%=h job['backtrace'].join("\n") %></pre>
38+
<% if job['backtrace'] %>
39+
<a href="#" class="backtrace"><%= h(job['error']) %></a>
40+
<pre style='display:none'><%=h job['backtrace'].join("\n") %></pre>
41+
<% else %>
42+
<%=h job['error'] %>
43+
<% end %>
4044
</dd>
4145
</dl>
4246
<div class='r'>

lib/resque/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Resque
2-
Version = '1.7.1'
2+
Version = '1.8.0'
33
end

lib/resque/worker.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,19 @@ def work(interval = 5, &block)
113113
if not @paused and job = reserve
114114
log "got: #{job.inspect}"
115115
run_hook :before_fork
116+
working_on job
116117

117118
if @child = fork
118119
rand # Reseeding
119120
procline "Forked #{@child} at #{Time.now.to_i}"
120121
Process.wait
121122
else
122123
procline "Processing #{job.queue} since #{Time.now.to_i}"
123-
process(job, &block)
124+
perform(job, &block)
124125
exit! unless @cant_fork
125126
end
126127

128+
done_working
127129
@child = nil
128130
else
129131
break if interval.to_i == 0
@@ -137,15 +139,21 @@ def work(interval = 5, &block)
137139
unregister_worker
138140
end
139141

140-
# Processes a single job. If none is given, it will try to produce
141-
# one.
142-
def process(job = nil)
142+
# DEPRECATED. Processes a single job. If none is given, it will
143+
# try to produce one. Usually run in the child.
144+
def process(job = nil, &block)
143145
return unless job ||= reserve
144146

147+
working_on job
148+
perform(job, &block)
149+
ensure
150+
done_working
151+
end
152+
153+
# Processes a given job in the child.
154+
def perform(job)
145155
begin
146-
job.worker = self
147156
run_hook :after_fork, job
148-
working_on job
149157
job.perform
150158
rescue Object => e
151159
log "#{job.inspect} failed: #{e.inspect}"
@@ -155,7 +163,6 @@ def process(job = nil)
155163
log "done: #{job.inspect}"
156164
ensure
157165
yield job if block_given?
158-
done_working
159166
end
160167
end
161168

@@ -348,6 +355,7 @@ def unregister_worker
348355
# Given a job, tells Redis we're working on it. Useful for seeing
349356
# what workers are doing and when.
350357
def working_on(job)
358+
job.worker = self
351359
data = encode \
352360
:queue => job.queue,
353361
:run_at => Time.now.to_i,

resque.gemspec

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'resque/version'
2+
3+
Gem::Specification.new do |s|
4+
s.name = "resque"
5+
s.version = Resque::Version
6+
s.date = Time.now.strftime('%Y-%m-%d')
7+
s.summary = "Resque is a Redis-backed queueing system."
8+
s.homepage = "http://github.com/defunkt/mustache"
9+
s.email = "[email protected]"
10+
s.authors = [ "Chris Wanstrath" ]
11+
12+
s.files = %w( README.markdown Rakefile LICENSE )
13+
s.files += Dir.glob("lib/**/*")
14+
s.files += Dir.glob("bin/**/*")
15+
s.files += Dir.glob("man/**/*")
16+
s.files += Dir.glob("test/**/*")
17+
s.executables = [ "resque", "resque-web" ]
18+
19+
s.extra_rdoc_files = [ "LICENSE", "README.markdown" ]
20+
s.rdoc_options = ["--charset=UTF-8"]
21+
22+
s.add_dependency "redis"
23+
s.add_dependency "redis-namespace"
24+
s.add_dependency "vegas", ">= 0.1.2"
25+
s.add_dependency "sinatra", ">= 0.9.2"
26+
27+
s.description = <<description
28+
Resque is a Redis-backed Ruby library for creating background jobs,
29+
placing those jobs on multiple queues, and processing them later.
30+
31+
Background jobs can be any Ruby class or module that responds to
32+
perform. Your existing classes can easily be converted to background
33+
jobs or you can create new classes specifically to do work. Or, you
34+
can do both.
35+
36+
Resque is heavily inspired by DelayedJob (which rocks) and is
37+
comprised of three parts:
38+
39+
* A Ruby library for creating, querying, and processing jobs
40+
* A Rake task for starting a worker which processes jobs
41+
* A Sinatra app for monitoring queues, jobs, and workers.
42+
description
43+
end

test/resque_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
@worker = Resque::Worker.new(:jobs)
203203
@worker.register_worker
204204
2.times { @worker.process }
205+
205206
job = @worker.reserve
206207
@worker.working_on job
207208

0 commit comments

Comments
 (0)