Skip to content

Commit

Permalink
Add exceptional failure handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 22, 2011
1 parent aaab762 commit a29007a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/qu-exceptional.rb
@@ -0,0 +1,4 @@
require 'qu'
require 'qu/failure/exceptional'

Qu.failure = Qu::Failure::Exceptional
33 changes: 33 additions & 0 deletions lib/qu/failure/exceptional.rb
@@ -0,0 +1,33 @@
require 'exceptional'

module Qu
module Failure
class Exceptional
def self.create(job, exception)
if ::Exceptional::Config.should_send_to_api?
::Exceptional::Remote.error(ExceptionData.new(job, exception))
end
end

class ExceptionData < ::Exceptional::ExceptionData
def initialize(job, exception)
@job = job
super(exception, 'Qu')
end

def framework
'qu'
end

def extra_stuff
{
'id' => @job.id,
'queue' => @job.queue,
'args' => @job.args,
'class' => @job.klass.to_s
}
end
end
end
end
end
19 changes: 19 additions & 0 deletions qu-exceptional.gemspec
@@ -0,0 +1,19 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "qu/version"

Gem::Specification.new do |s|
s.name = "qu-exceptional"
s.version = Qu::VERSION
s.authors = ["Brandon Keepers"]
s.email = ["brandon@opensoul.org"]
s.homepage = "http://github.com/bkeepers/qu"
s.summary = "Exceptional failure backend for qu"
s.description = "Exceptional failure backend for qu"

s.files = `git ls-files -- lib | grep exceptional`.split("\n")
s.require_paths = ["lib"]

s.add_dependency 'exceptional'
s.add_dependency 'qu', Qu::VERSION
end
47 changes: 47 additions & 0 deletions spec/qu/failure/exceptional_spec.rb
@@ -0,0 +1,47 @@
require 'spec_helper'
require 'qu-exceptional'

describe Qu::Failure::Exceptional do
let(:job) { Qu::Job.new('123', SimpleJob, ['987']) }

describe Qu::Failure::Exceptional::ExceptionData do
subject { Qu::Failure::Exceptional::ExceptionData.new(job, Exception.new) }

it 'should include job data in the request' do
subject.extra_stuff.should == {
'id' => '123',
'queue' => 'default',
'args' => ['987'],
'class' => 'SimpleJob'
}
end

it 'should set the framework' do
subject.framework.should == 'qu'
end
end

describe 'create' do
context 'with exceptional enabled' do
before do
Exceptional::Config.enabled = true
end

it 'should send error' do
Exceptional::Remote.should_receive(:error).with(instance_of(Qu::Failure::Exceptional::ExceptionData))
described_class.create(job, Exception.new)
end
end

context 'with exceptional disabled' do
before do
Exceptional::Config.enabled = false
end

it 'should not send error' do
Exceptional::Remote.should_not_receive(:error)
described_class.create(job, Exception.new)
end
end
end
end

0 comments on commit a29007a

Please sign in to comment.