Skip to content

Commit

Permalink
Merge branch 'defunkt' into distributed
Browse files Browse the repository at this point in the history
  • Loading branch information
mpd committed Sep 22, 2011
2 parents 22d1fe1 + 11f3fac commit 8996224
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 33 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -9,4 +9,7 @@ group :test do
gem "leftright", :platforms => :mri_18
gem "yajl-ruby", "~>0.8.2", :platforms => :mri
gem "json", "~>1.5.3", :platforms => [:jruby, :rbx]
gem "hoptoad_notifier"
gem "airbrake"
gem "i18n"
end
10 changes: 10 additions & 0 deletions HISTORY.md
@@ -1,3 +1,13 @@
## 1.19.0 (2011-09-01)

* Added Airbrake (formerly Hoptoad) support.
* Web UI: Added retry all button to failed jobs page
* Web UI: Show focus outline

## 1.18.6 (2011-08-30)

* Bugfix: Use Rails 3 eager loading for resque:preload

## 1.18.5 (2011-08-24)

* Added support for Travis CI
Expand Down
8 changes: 8 additions & 0 deletions README.markdown
Expand Up @@ -469,6 +469,14 @@ run Rack::URLMap.new \
Check `examples/demo/config.ru` for a functional example (including
HTTP basic auth).

### Rails 3

You can also easily mount Resque on a subpath in your existing Rails 3 app by adding this to your `routes.rb`:

``` ruby
mount Resque::Server.new, :at => "/resque"
```


Resque vs DelayedJob
--------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/god/resque.god
Expand Up @@ -14,7 +14,7 @@ num_workers.times do |num|
w.uid = 'git'
w.gid = 'git'

# retart if memory gets too high
# restart if memory gets too high
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 350.megabytes
Expand Down
17 changes: 17 additions & 0 deletions lib/resque/failure/airbrake.rb
@@ -0,0 +1,17 @@
begin
require 'airbrake'
rescue LoadError
raise "Can't find 'airbrake' gem. Please add it to your Gemfile or install it."
end

require 'resque/failure/thoughtbot'

module Resque
module Failure
class Airbrake < Base
include Resque::Failure::Thoughtbot

@klass = ::Airbrake
end
end
end
23 changes: 4 additions & 19 deletions lib/resque/failure/hoptoad.rb
Expand Up @@ -4,6 +4,8 @@
raise "Can't find 'hoptoad_notifier' gem. Please add it to your Gemfile or install it."
end

require 'resque/failure/thoughtbot'

module Resque
module Failure
# A Failure backend that sends exceptions raised by jobs to Hoptoad.
Expand All @@ -23,26 +25,9 @@ module Failure
# end
# For more information see https://github.com/thoughtbot/hoptoad_notifier
class Hoptoad < Base
def self.configure(&block)
Resque::Failure.backend = self
HoptoadNotifier.configure(&block)
end

def self.count
# We can't get the total # of errors from Hoptoad so we fake it
# by asking Resque how many errors it has seen.
Stat[:failed]
end

def save
HoptoadNotifier.notify_or_ignore(exception,
:parameters => {
:payload_class => payload['class'].to_s,
:payload_args => payload['args'].inspect
}
)
end
include Resque::Failure::Thoughtbot

@klass = ::HoptoadNotifier
end
end
end
33 changes: 33 additions & 0 deletions lib/resque/failure/thoughtbot.rb
@@ -0,0 +1,33 @@
module Resque
module Failure
module Thoughtbot
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
attr_accessor :klass

def configure(&block)
Resque::Failure.backend = self
klass.configure(&block)
end

def count
# We can't get the total # of errors from Hoptoad so we fake it
# by asking Resque how many errors it has seen.
Stat[:failed]
end
end

def save
self.class.klass.notify_or_ignore(exception,
:parameters => {
:payload_class => payload['class'].to_s,
:payload_args => payload['args'].inspect
}
)
end
end
end
end
7 changes: 7 additions & 0 deletions lib/resque/server.rb
Expand Up @@ -176,6 +176,13 @@ def show_for_polling(page)
redirect u('failed')
end

post "/failed/requeue/all" do
Resque::Failure.count.times do |num|
Resque::Failure.requeue(num)
end
redirect u('failed')
end

get "/failed/requeue/:index" do
Resque::Failure.requeue(params[:index])
if request.xhr?
Expand Down
4 changes: 0 additions & 4 deletions lib/resque/server/public/reset.css
Expand Up @@ -16,10 +16,6 @@ table, caption, tbody, tfoot, thead, tr, th, td {
font-family: inherit;
}

:focus {
outline: 0;
}

body {
line-height: 1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/resque/server/public/style.css
Expand Up @@ -80,6 +80,6 @@ body { padding:0; margin:0; }
#main p.pagination a.less { float:left;}
#main p.pagination a.more { float:right;}

#main form {float:right; margin-top:-10px;}
#main form {float:right; margin-top:-10px;margin-left:10px;}

#main .time a.toggle_format {text-decoration:none;}
5 changes: 4 additions & 1 deletion lib/resque/server/views/failed.erb
Expand Up @@ -5,9 +5,12 @@

<h1>Failed Jobs</h1>
<%unless failed.empty?%>
<form method="POST" action="<%=u 'failed/clear'%>" class='clear-failed'>
<form method="POST" action="<%=u 'failed/clear'%>">
<input type='submit' name='' value='Clear Failed Jobs' />
</form>
<form method="POST" action="<%=u 'failed/requeue/all'%>">
<input type='submit' name='' value='Retry Failed Jobs' />
</form>
<%end%>
<p class='sub'>Showing <%=start%> to <%= start + 20 %> of <b><%= size = Resque::Failure.count %></b> jobs</p>
Expand Down
11 changes: 7 additions & 4 deletions lib/resque/tasks.rb
Expand Up @@ -42,10 +42,13 @@

# Preload app files if this is Rails
task :preload => :setup do
if defined?(Rails) && Rails.env == 'production'
Dir["#{Rails.root}/app/**/*.rb"].each do |file|
require file
end
if defined?(Rails) && Rails.respond_to?(:application)
# Rails 3
Rails.application.eager_load!
elsif defined?(Rails::Initializer)
# Rails 2.3
$rails_rake_task = false
Rails::Initializer.run :load_application_classes
end
end
end
2 changes: 1 addition & 1 deletion lib/resque/version.rb
@@ -1,3 +1,3 @@
module Resque
Version = VERSION = '1.18.5'
Version = VERSION = '1.19.0'
end
2 changes: 1 addition & 1 deletion lib/resque/worker.rb
Expand Up @@ -191,7 +191,7 @@ def perform(job)
def reserve
queues.each do |queue|
log! "Checking #{queue}"
if job = Resque::Job.reserve(queue)
if job = Resque.reserve(queue)
log! "Found job on #{queue}"
return job
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/resque.rake
@@ -1,2 +1,2 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
require 'resque/tasks'
27 changes: 27 additions & 0 deletions test/airbrake_test.rb
@@ -0,0 +1,27 @@

require 'test_helper'

begin
require 'airbrake'
rescue LoadError
warn "Install airbrake gem to run Airbrake tests."
end

if defined? Airbrake
require 'resque/failure/airbrake'
context "Airbrake" do
test "should be notified of an error" do
exception = StandardError.new("BOOM")
worker = Resque::Worker.new(:test)
queue = "test"
payload = {'class' => Object, 'args' => 66}

Airbrake.expects(:notify_or_ignore).with(
exception,
:parameters => {:payload_class => 'Object', :payload_args => '66'})

backend = Resque::Failure::Airbrake.new(exception, worker, queue, payload)
backend.save
end
end
end
1 change: 1 addition & 0 deletions test/hoptoad_test.rb
Expand Up @@ -7,6 +7,7 @@
end

if defined? HoptoadNotifier
require 'resque/failure/hoptoad'
context "Hoptoad" do
test "should be notified of an error" do
exception = StandardError.new("BOOM")
Expand Down

0 comments on commit 8996224

Please sign in to comment.