Permalink
Browse files

airbrake failure backend

  • Loading branch information...
1 parent d33722d commit 418237afff9d2636a87319cf83251392bcbbc75d @stellard stellard committed Oct 25, 2011
Showing with 90 additions and 0 deletions.
  1. +4 −0 lib/qu-airbrake.rb
  2. +31 −0 lib/qu/failure/airbrake.rb
  3. +20 −0 qu-airbrake.gemspec
  4. +35 −0 spec/qu/failure/airbrake_spec.rb
View
@@ -0,0 +1,4 @@
+require 'qu'
+require 'qu/failure/airbrake'
+
+Qu.failure = Qu::Failure::Airbrake
@@ -0,0 +1,31 @@
+require 'airbrake'
+
+module Qu
+ module Failure
+ class Airbrake
+ extend Logger
+
+ def self.create(job, exception)
+ logger.debug "Reporting error to Airbrake"
+ ::Airbrake.notify_or_ignore(exception, extra_stuff(job))
+ end
+
+ def self.extra_stuff job
+ {
+ 'request' => {
+ 'parameters' => {
+ 'id' => job.id,
+ 'queue' => job.queue,
+ 'args' => job.args,
+ 'class' => job.klass.to_s
+ }
+ },
+
+ 'rescue_block' => {
+ 'name' => job.klass.to_s
+ }
+ }
+ end
+ end
+ end
+end
View
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "qu/version"
+
+Gem::Specification.new do |s|
+ s.name = "qu-airbrake"
+ s.version = Qu::VERSION
+ s.authors = ["Brandon Keepers", "Scott Ellard"]
+ s.email = ["brandon@opensoul.org"]
+ s.homepage = "http://github.com/bkeepers/qu"
+ s.summary = "Airbrake failure backend for qu"
+ s.description = "Airbrake failure backend for qu"
+
+ s.files = `git ls-files -- lib | grep airbrake`.split("\n")
+ s.require_paths = ["lib"]
+
+ s.add_dependency 'airbrake'
+ s.add_dependency 'i18n'
+ s.add_dependency 'qu', Qu::VERSION
+end
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+require 'qu-airbrake'
+
+describe Qu::Failure::Airbrake do
+
+ let(:job) { Qu::Payload.new(:id => '123', :klass => SimpleJob, :args => ['987']) }
+
+ describe ".extra_stuff" do
+ it 'should return job data' do
+ described_class.extra_stuff(job).should == {
+ 'request' => {
+ 'parameters' => {
+ 'id' => '123',
+ 'queue' => 'default',
+ 'args' => ['987'],
+ 'class' => 'SimpleJob'
+ }
+ },
+ 'rescue_block' => {
+ 'name' => 'SimpleJob'
+ }
+ }
+ end
+ end
+
+ describe '.create' do
+ let(:exception) { Exception.new }
+
+ it 'should send error' do
+ ::Airbrake.should_receive(:notify_or_ignore).with(exception, described_class.extra_stuff(job))
+ described_class.create(job, exception)
+ end
+ end
+end

0 comments on commit 418237a

Please sign in to comment.