yogi_berra 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile +2 -1
- data/README.md +60 -2
- data/lib/generators/yogi_berra/install_generator.rb +17 -0
- data/lib/generators/yogi_berra/templates/yogi_berra.rb +42 -0
- data/lib/yogi_berra/action_controller_catcher.rb +1 -1
- data/lib/yogi_berra/catcher.rb +21 -31
- data/lib/yogi_berra/data.rb +2 -2
- data/lib/yogi_berra/resque.rb +20 -0
- data/lib/yogi_berra/sidekiq.rb +21 -0
- data/lib/yogi_berra/version.rb +1 -1
- data/lib/yogi_berra.rb +15 -7
- data/spec/fixtures/rails.rb +1 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/yogi_berra_catcher_spec.rb +6 -6
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGY3ZThlMDQ1ZDFhYjgwOWJjYjk0MWFlNTBlNGEyY2Y0MzcwYWNjMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDk1YmJjM2RkZmE2OWFmMjQ3YmJkMzgwMzYyMzk3YzFjODBjZDJmYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2ZiNDMzYzIxZGFjMGY0ZjM2YjZhMTlhOGRhYjQxNjA0NjRlMTEwNTdjYjY1
|
10
|
+
NDZhZjhmYTc3ZmE3NzBiMGIxMjkzYWEwOGU5YjdlN2IzZGQ2ZmZjZWUwYjcx
|
11
|
+
ZmU0NTk3MWE5NGVlZjBhOTllOGUzZTdkODk5OWZiMTVmZTg5NTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzllNDEzMmFhMmIwNzJjOGI5NjY4YmJjMmU0MTJjYzMwZTQ0YTZjN2I1ZGRk
|
14
|
+
Yjc5OTU2ODBlZDk3ZjI4NDYwM2RlN2E3YzVmNzgwMmVhYmQ2NDQ5M2NkMWZi
|
15
|
+
OGM2MDc3MjQ4NzUyYjhlZDlkODdhYzcxMWNiZTY2ZWY4NmFmMGU=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
[](http://badge.fury.io/rb/yogi_berra)
|
1
2
|
[](https://travis-ci.org/earlonrails/yogi_berra)
|
3
|
+
[](https://coveralls.io/r/earlonrails/yogi_berra)
|
2
4
|
|
3
5
|
Yogi Berra
|
4
6
|
==========
|
@@ -17,8 +19,8 @@ the buffer will be entered into the database. There can be data loss if the buff
|
|
17
19
|
There are some messages in the logs which will tell you if the connection is down.
|
18
20
|
This makes the catcher work when it does and not crash or slow when it doesn't.
|
19
21
|
|
20
|
-
Installation
|
21
|
-
|
22
|
+
Installation With Rails
|
23
|
+
-----------------------
|
22
24
|
|
23
25
|
add yogi_berra to your Gemfile:
|
24
26
|
|
@@ -37,6 +39,61 @@ Create a yogi.yml file in rails root config/ folder. Here is a sample:
|
|
37
39
|
host: localhost
|
38
40
|
port: 27017
|
39
41
|
|
42
|
+
Rails 3+
|
43
|
+
--------
|
44
|
+
Generate an initializer
|
45
|
+
|
46
|
+
rails g yogi_berra:install [--resque|--sidekiq]
|
47
|
+
|
48
|
+
|
49
|
+
Rails 2.3
|
50
|
+
---------
|
51
|
+
Create an initializer manually, here is an example:
|
52
|
+
|
53
|
+
require 'yogi_berra/rails'
|
54
|
+
|
55
|
+
# Sidekiq error handling support
|
56
|
+
# require 'yogi_berra/sidekiq'
|
57
|
+
|
58
|
+
# Resque error handling support
|
59
|
+
# require 'resque/failure/multiple'
|
60
|
+
# require 'resque/failure/redis'
|
61
|
+
# require 'yogi_berra/resque'
|
62
|
+
|
63
|
+
# Resque::Failure::Multiple.classes = [Resque::Failure::Redis, YogiBerra::Resque]
|
64
|
+
# Resque::Failure.backend = Resque::Failure::Multiple
|
65
|
+
|
66
|
+
YogiBerra.configure do |config|
|
67
|
+
# Ignore exception types.
|
68
|
+
# ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and ActionController::RoutingError are already added.
|
69
|
+
# config.ignored_exceptions += %w{ActionView::TemplateError CustomError}
|
70
|
+
|
71
|
+
# Mongodb setup
|
72
|
+
# should point to the yogi.yml file which should contain the mongodb configuration settings ie
|
73
|
+
#
|
74
|
+
# defaults: &defaults
|
75
|
+
# username: yogi
|
76
|
+
# password: berra
|
77
|
+
# project: rails_yogi_project
|
78
|
+
#
|
79
|
+
# test:
|
80
|
+
# <<: *defaults
|
81
|
+
# database: yogi_berra
|
82
|
+
# host: localhost
|
83
|
+
# port: 27017
|
84
|
+
#
|
85
|
+
# Optionally a replica set may be used by replacing host with
|
86
|
+
#
|
87
|
+
# replica_set:
|
88
|
+
# - host1:27017
|
89
|
+
# - host2:27017
|
90
|
+
# - host3:27017
|
91
|
+
#
|
92
|
+
|
93
|
+
config.yogi_yml = "#{Rails.root}/config/yogi.yml"
|
94
|
+
end
|
95
|
+
|
96
|
+
|
40
97
|
Without Rails
|
41
98
|
-------------
|
42
99
|
|
@@ -63,6 +120,7 @@ Thanks
|
|
63
120
|
------
|
64
121
|
|
65
122
|
To :
|
123
|
+
|
66
124
|
- Thoughtbot Airbrake:
|
67
125
|
https://github.com/airbrake/airbrake/tree/master/lib/airbrake
|
68
126
|
This gem is awesome and was the base for most of the code here.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# require 'rails/generators/base'
|
2
|
+
|
3
|
+
module YogiBerra
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Creates a YogiBerra initializer."
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
class_option :resque, :type => :boolean, :desc => 'Add support for handling errors in Resque jobs.'
|
10
|
+
class_option :sidekiq, :type => :boolean, :desc => 'Add support for handling errors in Sidekiq jobs.'
|
11
|
+
|
12
|
+
def copy_initializer
|
13
|
+
template 'yogi_berra.rb', 'config/initializers/yogi_berra.rb'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yogi_berra/engine'
|
2
|
+
|
3
|
+
# Sidekiq error handling support
|
4
|
+
# require 'yogi_berra/sidekiq'
|
5
|
+
|
6
|
+
# Resque error handling support
|
7
|
+
# require 'resque/failure/multiple'
|
8
|
+
# require 'resque/failure/redis'
|
9
|
+
# require 'yogi_berra/resque'
|
10
|
+
|
11
|
+
# Resque::Failure::Multiple.classes = [Resque::Failure::Redis, YogiBerra::Resque]
|
12
|
+
# Resque::Failure.backend = Resque::Failure::Multiple
|
13
|
+
|
14
|
+
YogiBerra.configure do |config|
|
15
|
+
# Ignore exception types.
|
16
|
+
# ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and ActionController::RoutingError are already added.
|
17
|
+
# config.ignored_exceptions += %w{ActionView::TemplateError CustomError}
|
18
|
+
|
19
|
+
# Mongodb setup
|
20
|
+
# should point to the yogi.yml file which should contain the mongodb configuration settings ie
|
21
|
+
#
|
22
|
+
# defaults: &defaults
|
23
|
+
# username: yogi
|
24
|
+
# password: berra
|
25
|
+
# project: rails_yogi_project
|
26
|
+
#
|
27
|
+
# test:
|
28
|
+
# <<: *defaults
|
29
|
+
# database: yogi_berra
|
30
|
+
# host: localhost
|
31
|
+
# port: 27017
|
32
|
+
#
|
33
|
+
# Optionally a replica set may be used by replacing host with
|
34
|
+
#
|
35
|
+
# replica_set:
|
36
|
+
# - host1:27017
|
37
|
+
# - host2:27017
|
38
|
+
# - host3:27017
|
39
|
+
#
|
40
|
+
|
41
|
+
config.yogi_yml = "#{Rails.root}/config/yogi.yml"
|
42
|
+
end
|
@@ -6,7 +6,7 @@ module YogiBerra
|
|
6
6
|
if base.method_defined?(:rescue_action_in_public)
|
7
7
|
base.send(:alias_method, :rescue_action_in_public_without_yogi, :rescue_action_in_public)
|
8
8
|
base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_yogi)
|
9
|
-
if YogiBerra
|
9
|
+
if YogiBerra.settings
|
10
10
|
base.send(:alias_method, :rescue_action_locally_without_yogi, :rescue_action_locally)
|
11
11
|
base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_yogi)
|
12
12
|
end
|
data/lib/yogi_berra/catcher.rb
CHANGED
@@ -1,34 +1,24 @@
|
|
1
1
|
require 'mongo'
|
2
|
-
require 'facets'
|
3
2
|
require 'yaml'
|
4
3
|
require 'timeout'
|
5
4
|
|
6
5
|
module YogiBerra
|
7
6
|
class Catcher
|
8
|
-
extend Facets
|
9
|
-
cattr_accessor :settings, :mongo_client, :connection
|
10
|
-
|
11
7
|
class << self
|
12
8
|
def load_db_settings(config_file = nil)
|
13
9
|
if config_file
|
14
|
-
|
15
|
-
elsif defined?(::Rails)
|
16
|
-
database_config = Rails.root ? "#{Rails.root}/config/yogi.yml" : "config/yogi.yml"
|
17
|
-
else
|
18
|
-
YogiBerra::Logger.log("No config file specified!", :error)
|
10
|
+
YogiBerra.yogi_yml = config_file
|
19
11
|
end
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@@settings = yaml_file["#{environment}"] if yaml_file
|
26
|
-
end
|
27
|
-
rescue
|
28
|
-
YogiBerra::Logger.log("No such file: #{database_config}", :error)
|
13
|
+
begin
|
14
|
+
File.open(YogiBerra.yogi_yml, 'r') do |f|
|
15
|
+
yaml_file = YAML.load(f)
|
16
|
+
YogiBerra.settings = yaml_file["#{environment}"] if yaml_file
|
29
17
|
end
|
30
|
-
|
18
|
+
rescue
|
19
|
+
YogiBerra::Logger.log("No such file: #{database_config}", :error)
|
31
20
|
end
|
21
|
+
YogiBerra.settings
|
32
22
|
end
|
33
23
|
|
34
24
|
def environment
|
@@ -44,21 +34,21 @@ module YogiBerra
|
|
44
34
|
end
|
45
35
|
|
46
36
|
def fork_database
|
47
|
-
host =
|
48
|
-
port =
|
49
|
-
database =
|
50
|
-
username =
|
51
|
-
password =
|
52
|
-
replica_set =
|
37
|
+
host = YogiBerra.settings["host"]
|
38
|
+
port = YogiBerra.settings["port"]
|
39
|
+
database = YogiBerra.settings["database"]
|
40
|
+
username = YogiBerra.settings["username"]
|
41
|
+
password = YogiBerra.settings["password"]
|
42
|
+
replica_set = YogiBerra.settings["replica_set"]
|
53
43
|
|
54
44
|
# :w => 0 set the default write concern to 0, this allows writes to be non-blocking
|
55
45
|
# by not waiting for a response from mongodb
|
56
46
|
Thread.new do
|
57
47
|
begin
|
58
48
|
if replica_set
|
59
|
-
|
49
|
+
YogiBerra.mongo_client = Mongo::MongoReplicaSetClient.new(replica_set, :w => 0, :connect_timeout => 10)
|
60
50
|
else
|
61
|
-
|
51
|
+
YogiBerra.mongo_client = Mongo::MongoClient.new(host, port, :w => 0, :connect_timeout => 10)
|
62
52
|
end
|
63
53
|
rescue Timeout::Error => timeout_error
|
64
54
|
YogiBerra::Logger.log("Couldn't connect to the mongo database timeout on host: #{host} port: #{port}.\n #{timeout_error.inspect}", :error)
|
@@ -69,10 +59,10 @@ module YogiBerra
|
|
69
59
|
retry
|
70
60
|
end
|
71
61
|
|
72
|
-
|
62
|
+
YogiBerra.connection = YogiBerra.mongo_client[database]
|
73
63
|
if username && password
|
74
64
|
begin
|
75
|
-
|
65
|
+
YogiBerra.connection.authenticate(username, password)
|
76
66
|
rescue
|
77
67
|
YogiBerra::Logger.log("Couldn't authenticate with user #{username} to mongo database on host: #{host} port: #{port} database: #{database}.", :warn)
|
78
68
|
end
|
@@ -81,14 +71,14 @@ module YogiBerra
|
|
81
71
|
end
|
82
72
|
|
83
73
|
def connect(load_settings = false)
|
84
|
-
load_db_settings if
|
74
|
+
load_db_settings if load_db_settings
|
85
75
|
|
86
|
-
if
|
76
|
+
if YogiBerra.settings
|
87
77
|
fork_database
|
88
78
|
else
|
89
79
|
YogiBerra::Logger.log("Couldn't load the yogi.yml file.", :error) if load_settings
|
90
80
|
end
|
91
|
-
|
81
|
+
YogiBerra.connection
|
92
82
|
end
|
93
83
|
end
|
94
84
|
end
|
data/lib/yogi_berra/data.rb
CHANGED
@@ -14,13 +14,13 @@ module YogiBerra
|
|
14
14
|
end
|
15
15
|
# convert all the keys to strings for bson storage, using activesupport keys.rb file
|
16
16
|
data.deep_stringify_keys_and_values!
|
17
|
-
YogiBerra
|
17
|
+
YogiBerra.connection["caught_exceptions"].insert(data)
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.parse_exception(notice)
|
21
21
|
data_hash = {
|
22
22
|
:error_class => "#{notice.exception.class}",
|
23
|
-
:project => YogiBerra
|
23
|
+
:project => YogiBerra.settings["project"],
|
24
24
|
:error_message => notice.respond_to?(:error_message) ? notice.error_message : notice.message
|
25
25
|
}
|
26
26
|
data_hash[:backtraces] = notice.backtrace
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'resque/failure/base'
|
2
|
+
|
3
|
+
module YogiBerra
|
4
|
+
class Resque < Resque::Failure::Base
|
5
|
+
def self.count
|
6
|
+
Stat[:failed]
|
7
|
+
end
|
8
|
+
|
9
|
+
def save
|
10
|
+
data = {
|
11
|
+
:queue => queue,
|
12
|
+
:worker => worker.to_s,
|
13
|
+
:args => payload["args"],
|
14
|
+
:class => payload["class"].to_s
|
15
|
+
}
|
16
|
+
|
17
|
+
YogiBerra.exceptionize(exception, :resque => data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
module YogiBerra
|
4
|
+
class Sidekiq
|
5
|
+
def call(worker, message, queue)
|
6
|
+
begin
|
7
|
+
yield
|
8
|
+
rescue Exception => exception
|
9
|
+
message["worker"] = message.delete("jid")
|
10
|
+
YogiBerra.exceptionize(exception, :sidekiq => message)
|
11
|
+
raise exception
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
::Sidekiq.configure_server do |config|
|
18
|
+
config.server_middleware do |chain|
|
19
|
+
chain.add ::YogiBerra::Sidekiq
|
20
|
+
end
|
21
|
+
end
|
data/lib/yogi_berra/version.rb
CHANGED
data/lib/yogi_berra.rb
CHANGED
@@ -4,14 +4,14 @@ require 'yogi_berra/notice'
|
|
4
4
|
require 'yogi_berra/exception_middleware'
|
5
5
|
require 'yogi_berra/data'
|
6
6
|
require 'yogi_berra/logger'
|
7
|
-
|
8
|
-
|
9
|
-
require 'yogi_berra/engine'
|
10
|
-
else
|
11
|
-
require 'yogi_berra/rails'
|
12
|
-
end
|
7
|
+
require 'facets'
|
8
|
+
include Facets
|
13
9
|
|
14
10
|
module YogiBerra
|
11
|
+
mattr_accessor :ignored_exceptions, :yogi_yml, :settings, :mongo_client, :connection
|
12
|
+
@@ignored_exceptions = %w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError}
|
13
|
+
@@yogi_yml = "config/yogi.yml"
|
14
|
+
|
15
15
|
class << self
|
16
16
|
# Stores the notice exception
|
17
17
|
# @see YogiBerra.exceptionize
|
@@ -19,13 +19,21 @@ module YogiBerra
|
|
19
19
|
# @params environment
|
20
20
|
# @params opts
|
21
21
|
def exceptionize(exception, environment = nil, opts = {})
|
22
|
+
return false if ignored_exception?(exception)
|
22
23
|
notice = build_notice_for(exception, opts)
|
23
|
-
if YogiBerra
|
24
|
+
if YogiBerra.connection
|
24
25
|
YogiBerra::Data.store!(notice, environment)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
def configure
|
30
|
+
yield self
|
31
|
+
end
|
32
|
+
|
28
33
|
private
|
34
|
+
def ignored_exception?(exception)
|
35
|
+
@@ignored_exceptions.collect(&:to_s).include?(exception.class.name)
|
36
|
+
end
|
29
37
|
|
30
38
|
def build_notice_for(exception, opts = {})
|
31
39
|
exception = unwrap_exception(exception)
|
data/spec/fixtures/rails.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -11,16 +11,16 @@ describe YogiBerra::Catcher do
|
|
11
11
|
|
12
12
|
it "should load a yaml file without rails" do
|
13
13
|
lambda { YogiBerra::Catcher.load_db_settings(@test_yaml) }.should_not raise_error
|
14
|
-
YogiBerra
|
15
|
-
YogiBerra
|
14
|
+
YogiBerra.settings.should_not == nil
|
15
|
+
YogiBerra.settings["project"].should == "test_yogi_project"
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should load a yaml file with rails" do
|
19
19
|
ENV["YOGI_ENV"] = nil
|
20
20
|
load "#{SPEC_FOLDER}/fixtures/rails.rb"
|
21
21
|
lambda { YogiBerra::Catcher.load_db_settings }.should_not raise_error
|
22
|
-
YogiBerra
|
23
|
-
YogiBerra
|
22
|
+
YogiBerra.settings.should_not == nil
|
23
|
+
YogiBerra.settings["project"].should == "rails_yogi_project"
|
24
24
|
Object.send(:remove_const, :Rails)
|
25
25
|
end
|
26
26
|
|
@@ -29,7 +29,7 @@ describe YogiBerra::Catcher do
|
|
29
29
|
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
30
30
|
mock_yogi_fork_database
|
31
31
|
lambda { YogiBerra::Catcher.connect }.should_not raise_error
|
32
|
-
YogiBerra
|
32
|
+
YogiBerra.connection.should_not == nil
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should grab a connection to mongodb" do
|
@@ -37,7 +37,7 @@ describe YogiBerra::Catcher do
|
|
37
37
|
YogiBerra::Catcher.load_db_settings(@test_yaml)
|
38
38
|
mock_yogi_fork_database
|
39
39
|
YogiBerra::Catcher.connect
|
40
|
-
YogiBerra
|
40
|
+
YogiBerra.mongo_client.should_not == nil
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should grab a connection and authenticate" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yogi_berra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Earl Krauss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -88,6 +88,8 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- lib/facets.rb
|
91
|
+
- lib/generators/yogi_berra/install_generator.rb
|
92
|
+
- lib/generators/yogi_berra/templates/yogi_berra.rb
|
91
93
|
- lib/keys.rb
|
92
94
|
- lib/yogi_berra/action_controller_catcher.rb
|
93
95
|
- lib/yogi_berra/backtrace.rb
|
@@ -98,6 +100,8 @@ files:
|
|
98
100
|
- lib/yogi_berra/logger.rb
|
99
101
|
- lib/yogi_berra/notice.rb
|
100
102
|
- lib/yogi_berra/rails.rb
|
103
|
+
- lib/yogi_berra/resque.rb
|
104
|
+
- lib/yogi_berra/sidekiq.rb
|
101
105
|
- lib/yogi_berra/version.rb
|
102
106
|
- lib/yogi_berra.rb
|
103
107
|
- Gemfile
|