Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit dc246c0f362a6099d7411005003031649b4ca597 @hmarr hmarr committed Jun 18, 2012
Showing with 124 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE
  4. +21 −0 README.md
  5. +1 −0 lib/resque-sentry.rb
  6. +32 −0 lib/resque/failure/sentry.rb
  7. +16 −0 resque-sentry.gemspec
  8. +18 −0 spec/sentry_spec.rb
  9. +8 −0 spec/spec_helper.rb
@@ -0,0 +1,2 @@
+Gemfile.lock
+.bundle
@@ -0,0 +1,4 @@
+source :rubygems
+
+gemspec
+
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 GoCardless
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
+# resque-sentry
+
+A Resque failure backend that sends errors to [Sentry](https://getsentry.com).
+
+### Installation
+
+```console
+$ gem install resque-sentry
+```
+
+### Usage
+
+Add the following to an initializer:
+
+```ruby
+require 'resque-sentry'
+
+Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Sentry]
+Resque::Failure.backend = Resque::Failure::Multiple
+```
+
@@ -0,0 +1 @@
+require 'resque/failure/sentry'
@@ -0,0 +1,32 @@
+begin
+ require 'raven'
+rescue LoadError
+ raise "Can't find 'sentry-raven' gem. Please add it to your Gemfile or install it."
+end
+
+module Resque
+ module Failure
+ # Failure backend for Sentry (using the raven client gem for Sentry).
+ # Similar to the Airbrake backend, this sends exceptions raised in Resque
+ # jobs to Sentry. To use, add the following to an initializer:
+ #
+ # require 'resque/failure/sentry'
+ #
+ # Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Sentry]
+ # Resque::Failure.backend = Resque::Failure::Multiple
+ #
+ class Sentry < Base
+ def save
+ event = Raven::Event.capture_exception(exception)
+ Raven.send(event) if event
+ end
+
+ def self.count
+ # We can't get the total # of errors from Sentry so we fake it by
+ # asking Resque how many errors it has seen.
+ Stat[:failed]
+ end
+ end
+ end
+end
+
@@ -0,0 +1,16 @@
+Gem::Specification.new do |gem|
+ gem.name = 'resque-sentry'
+ gem.version = '0.1.0'
+ gem.authors = ['Harry Marr']
+ gem.email = ['harry@gocardless.com']
+ gem.summary = 'A failure backend for Resque that sends events to Sentry'
+ gem.homepage = 'https://github.com/gocardless/resque-sentry'
+
+ gem.add_dependency 'resque', '>= 1.18.0'
+ gem.add_dependency 'sentry-raven', '>= 0.1'
+ gem.add_development_dependency 'rspec', '~> 2.6'
+ gem.add_development_dependency 'mocha', '~> 0.11.0'
+
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
+end
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Resque::Failure::Sentry do
+ it "sends errors to Sentry" do
+ exception = StandardError.new("Test Error")
+ worker = Resque::Worker.new(:test)
+ queue = "test"
+ payload = {'class' => Object, 'args' => 1}
+
+ event = mock
+ Raven::Event.expects(:capture_exception).with(exception).returns(event)
+ Raven.expects(:send).with(event)
+
+ backend = Resque::Failure::Sentry.new(exception, worker, queue, payload)
+ backend.save
+ end
+end
+
@@ -0,0 +1,8 @@
+require 'mocha'
+require 'resque'
+require 'resque-sentry'
+
+RSpec.configure do |config|
+ config.mock_with :mocha
+end
+

0 comments on commit dc246c0

Please sign in to comment.