Skip to content

Commit

Permalink
Merge upstream 'resque/master'
Browse files Browse the repository at this point in the history
Conflicts:
	README.markdown
	lib/resque.rb
	lib/resque/worker.rb
  • Loading branch information
ctrochalakis committed Feb 12, 2010
2 parents 2c7d523 + 4c43b04 commit 18b67ee
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 44 deletions.
14 changes: 14 additions & 0 deletions HISTORY.md
@@ -1,3 +1,17 @@
## 1.4.0 (2010-02-11)

* Fallback when unable to bind QUIT and USR1 for Windows and JRuby.
* Fallback when no `Kernel.fork` is provided (for IronRuby).
* Web: Rounded corners in Firefox
* Cut down system calls in `Worker#prune_dead_workers`
* Enable switching DB in a Redis server from config
* Support USR2 and CONT to stop and start job processing.
* Web: Add example failing job
* Bugfix: `Worker#unregister_worker` shouldn't call `done_working`
* Bugfix: Example god config now restarts Resque properly.
* Multiple failure backends now permitted.
* Hoptoad failure backend updated to new API

## 1.3.1 (2010-01-11)

* Vegas bugfix: Don't error without a config
Expand Down
29 changes: 27 additions & 2 deletions README.markdown
Expand Up @@ -383,6 +383,8 @@ Resque workers respond to a few different signals:
* `QUIT` - Wait for child to finish processing then exit
* `TERM` / `INT` - Immediately kill child then exit
* `USR1` - Immediately kill child but don't exit
* `USR2` - Don't start to process any new jobs
* `CONT` - Start to process new jobs again after a USR2

If you want to gracefully shutdown a Resque worker, use `QUIT`.

Expand All @@ -392,6 +394,10 @@ Resque assumes the parent process is in a bad state and shuts down.

If you want to kill a stale or stuck child and shutdown, use `TERM`

If you want to stop processing jobs, but want to leave the worker running
(for example, to temporarily alleviate load), use `USR2` to stop processing,
then `CONT` to start it again.

### Mysql::Error: MySQL server has gone away

If your workers remain idle for too long they may lose their MySQL
Expand Down Expand Up @@ -627,7 +633,7 @@ can re-use the existing connection.

String: `Resque.redis = 'localhost:6379'`

Redis: `Redus.redis = $redis`
Redis: `Resque.redis = $redis`

For our rails app we have a `config/initializers/resque.rb` file where
we load `config/resque.yml` by hand and set the Redis information
Expand Down Expand Up @@ -657,6 +663,25 @@ this way we can tell our Sinatra app about the config file:
Now everyone is on the same page.


Namespaces
----------

If you're running multiple, separate instances of Resque you may want
to namespace the keyspaces so they do not overlap. This is not unlike
the approach taken by many memcached clients.

This feature is provided by the [redis-namespace][rs] library, which
Resque uses by default to separate the keys it manages from other keys
in your Redis server.

Simply use the `Resque.redis.namespace` accessor:

Resque.redis.namespace = "resque:GitHub"

We recommend sticking this in your initializer somewhere after Redis
is configured.


Demo
----

Expand Down Expand Up @@ -752,4 +777,4 @@ Chris Wanstrath :: chris@ozmm.org :: @defunkt
[1]: http://help.github.com/forking/
[2]: http://github.com/defunkt/resque/issues
[sv]: http://semver.org/
[resque]: http://github.com/defunct/resque
[rs]: http://github.com/defunkt/redis-namespace
11 changes: 11 additions & 0 deletions examples/demo/app.rb
Expand Up @@ -15,6 +15,12 @@ class App < Sinatra::Base
out << '<input type="submit" value="Create New Job"/>'
out << '&nbsp;&nbsp;<a href="/resque/">View Resque</a>'
out << '</form>'

out << "<form action='/failing' method='POST''>"
out << '<input type="submit" value="Create Failing New Job"/>'
out << '&nbsp;&nbsp;<a href="/resque/">View Resque</a>'
out << '</form>'

out << "</body></html>"
out
end
Expand All @@ -23,5 +29,10 @@ class App < Sinatra::Base
Resque.enqueue(Job, params)
redirect "/"
end

post '/failing' do
Resque.enqueue(FailingJob, params)
redirect "/"
end
end
end
10 changes: 10 additions & 0 deletions examples/demo/job.rb
Expand Up @@ -9,4 +9,14 @@ def self.perform(params)
puts "Processed a job!"
end
end

module FailingJob
@queue = :failing

def self.perform(params)
sleep 1
raise 'not processable!'
puts "Processed a job!"
end
end
end
3 changes: 2 additions & 1 deletion examples/god/resque.god
Expand Up @@ -7,7 +7,8 @@ num_workers.times do |num|
w.name = "resque-#{num}"
w.group = 'resque'
w.interval = 30.seconds
w.start = "env QUEUE=critical,high,low /usr/bin/rake -f #{rails_root}/Rakefile #{rails_env} resque:work"
w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env}
w.start = "/usr/bin/rake -f #{rails_root}/Rakefile environment resque:work"

w.uid = 'git'
w.gid = 'git'
Expand Down
6 changes: 6 additions & 0 deletions lib/resque.rb
Expand Up @@ -198,6 +198,12 @@ def working
Worker.working
end

# A shortcut to unregister_worker
# useful for command line tool
def remove_worker(worker_id)
worker = Resque::Worker.find(worker_id)
worker.unregister_worker
end

#
# stats
Expand Down
72 changes: 53 additions & 19 deletions lib/resque/failure/hoptoad.rb
@@ -1,4 +1,5 @@
require 'net/http'
require 'builder'

module Resque
module Failure
Expand All @@ -12,6 +13,9 @@ module Failure
# config.subdomain = 'your_hoptoad_subdomain'
# end
class Hoptoad < Base
#from the hoptoad plugin
INPUT_FORMAT = %r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze

class << self
attr_accessor :secure, :api_key, :subdomain
end
Expand All @@ -31,38 +35,25 @@ def self.configure
Resque::Failure.backend = self
end

def save
data = {
:api_key => api_key,
:error_class => exception.class.name,
:error_message => "#{exception.class.name}: #{exception.message}",
:backtrace => exception.backtrace,
:environment => {},
:session => {},
:request => {
:params => payload.merge(:worker => worker.to_s, :queue => queue.to_s)
}
}


send_to_hoptoad(:notice => data)
end

def send_to_hoptoad(data)
def save
http = use_ssl? ? :https : :http
url = URI.parse("#{http}://hoptoadapp.com/notices/")
url = URI.parse("#{http}://hoptoadapp.com/notifier_api/v2/notices")

http = Net::HTTP.new(url.host, url.port)
headers = {
'Content-type' => 'application/json',
'Content-type' => 'text/xml',
'Accept' => 'text/xml, application/xml'
}

http.read_timeout = 5 # seconds
http.open_timeout = 2 # seconds

http.use_ssl = use_ssl?

begin
response = http.post(url.path, Resque.encode(data), headers)
response = http.post(url.path, xml, headers)
rescue TimeoutError => e
log "Timeout while contacting the Hoptoad server."
end
Expand All @@ -75,6 +66,49 @@ def send_to_hoptoad(data)
log "Hoptoad Failure: #{response.class}\n#{body}"
end
end

def xml
x = Builder::XmlMarkup.new
x.instruct!
x.notice :version=>"2.0" do
x.tag! "api-key", api_key
x.notifier do
x.name "Resqueue"
x.version "0.1"
x.url "http://github.com/defunkt/resque"
end
x.error do
x.class exception.class.name
x.message "#{exception.class.name}: #{exception.message}"
x.backtrace do
fill_in_backtrace_lines(x)
end
end
x.request do
x.url queue.to_s
x.component worker.to_s
x.params do
x.var :key=>"payload_class" do
x.text! payload["class"].to_s
end
x.var :key=>"payload_args" do
x.text! payload["args"].to_s
end
end
end
x.tag!("server-environment") do
x.tag!("environment-name",RAILS_ENV)
end

end
end

def fill_in_backtrace_lines(x)
exception.backtrace.each do |unparsed_line|
_, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a
x.line :file=>file,:number=>number
end
end

def use_ssl?
self.class.secure
Expand Down
44 changes: 44 additions & 0 deletions lib/resque/failure/multiple.rb
@@ -0,0 +1,44 @@
module Resque
module Failure
# A Failure backend that uses multiple backends
# delegates all queries to the first backend
class Multiple < Base

class << self
attr_accessor :classes
end

def self.configure
yield self
Resque::Failure.backend = self
end

def initialize(*args)
@backends = self.class.classes.map {|klass| klass.new(*args)}
end
def save
@backends.each(&:save)
end

# The number of failures.
def self.count
classes.first.count
end

# Returns a paginated array of failure objects.
def self.all(start = 0, count = 1)
classes.first.all(start,count)
end

# A URL where someone can go to view failures.
def self.url
classes.first.url
end

# Clear all failure objects
def self.clear
classes.first.clear
end
end
end
end
2 changes: 1 addition & 1 deletion lib/resque/server/public/style.css
Expand Up @@ -4,7 +4,7 @@ body { padding:0; margin:0; }
.header { background:#000; padding:8px 5% 0 5%; border-bottom:1px solid #444;border-bottom:5px solid #429234;}
.header h1 { color:#333; font-size:90%; font-weight:bold; margin-bottom:6px;}
.header ul li { display:inline;}
.header ul li a { color:#fff; text-decoration:none; margin-right:10px; display:inline-block; padding:8px; -webkit-border-top-right-radius:6px; -webkit-border-top-left-radius:6px; }
.header ul li a { color:#fff; text-decoration:none; margin-right:10px; display:inline-block; padding:8px; -webkit-border-top-right-radius:6px; -webkit-border-top-left-radius:6px; -moz-border-radius-topleft:6px; -moz-border-radius-topright:6px; }
.header ul li a:hover { background:#333;}
.header ul li.current a { background:#429234; font-weight:bold; color:#fff;}

Expand Down
2 changes: 1 addition & 1 deletion lib/resque/version.rb
@@ -1,3 +1,3 @@
module Resque
Version = '1.3.1'
Version = '1.4.0'
end

0 comments on commit 18b67ee

Please sign in to comment.