forked from bkeepers/qu
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'qu' | ||
require 'qu/failure/exceptional' | ||
|
||
Qu.failure = Qu::Failure::Exceptional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |