sidekiq_metered_exceptions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1,8 @@
1
+ rvm_install_on_use_flag=1
2
+ rvm use --create ruby-1.9.3-p286-perf@sidekiq_metered_exceptions
3
+
4
+ export RUBY_HEAP_MIN_SLOTS=1000000
5
+ export RUBY_HEAP_SLOTS_INCREMENT=1000000
6
+ export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
7
+ export RUBY_GC_MALLOC_LIMIT=1000000000
8
+ export RUBY_HEAP_FREE_MIN=500000
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+
4
+ gem 'sidekiq'
5
+
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "minitest", ">= 0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.2.3"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ celluloid (0.14.1)
5
+ timers (>= 1.0.0)
6
+ connection_pool (1.1.0)
7
+ git (1.2.5)
8
+ jeweler (1.8.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.8.0)
14
+ minitest (5.0.4)
15
+ rake (10.0.4)
16
+ rdoc (3.12.2)
17
+ json (~> 1.4)
18
+ redis (3.0.4)
19
+ redis-namespace (1.3.0)
20
+ redis (~> 3.0.0)
21
+ sidekiq (2.12.4)
22
+ celluloid (>= 0.14.1)
23
+ connection_pool (>= 1.0.0)
24
+ json
25
+ redis (>= 3.0)
26
+ redis-namespace
27
+ timers (1.1.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.2.3)
34
+ jeweler (~> 1.8.4)
35
+ minitest
36
+ rdoc (~> 3.12)
37
+ sidekiq
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 ControlShift Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = sidekiq_metered_exceptions
2
+
3
+ A tiny sidekiq middleware that silences transient errors.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2013 ControlShift Ltd. See LICENSE.txt for
8
+ further details.
9
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sidekiq_metered_exceptions"
18
+ gem.homepage = "http://github.com/woodhull/sidekiq_metered_exceptions"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Only propagate sidekiq exceptions that have already been retried once.}
21
+ gem.description = %Q{Some exceptions are transient, so notifying an admin is not useful.}
22
+ gem.email = "woodhull@gmail.com"
23
+ gem.authors = ["Nathan Woodhull"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "sidekiq_metered_exceptions #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/middleware.rb ADDED
@@ -0,0 +1,13 @@
1
+ module SidekiqMeteredExceptions
2
+ class Middleware
3
+
4
+ def call(worker, job, queue)
5
+ begin
6
+ yield
7
+ rescue Exception => ex
8
+ # do not notify on the first occurrence of an exception
9
+ raise(ex) if job['retry_count'] == nil || job['retry_count'] > 0
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require 'sidekiq'
2
+ require 'middleware'
3
+
4
+ ::Sidekiq.configure_server do |config|
5
+ config.server_middleware do |chain|
6
+ chain.add ::SidekiqMeteredExceptions::Middleware
7
+ end
8
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sidekiq_metered_exceptions"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nathan Woodhull"]
12
+ s.date = "2013-06-18"
13
+ s.description = "Some exceptions are transient, so notifying an admin is not useful."
14
+ s.email = "woodhull@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/middleware.rb",
29
+ "lib/sidekiq_metered_exceptions.rb",
30
+ "sidekiq_metered_exceptions.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_sidekiq_metered_exceptions.rb"
33
+ ]
34
+ s.homepage = "http://github.com/woodhull/sidekiq_metered_exceptions"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.24"
38
+ s.summary = "Only propagate sidekiq exceptions that have already been retried once."
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<sidekiq>, [">= 0"])
45
+ s.add_development_dependency(%q<minitest>, [">= 0"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
49
+ else
50
+ s.add_dependency(%q<sidekiq>, [">= 0"])
51
+ s.add_dependency(%q<minitest>, [">= 0"])
52
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<sidekiq>, [">= 0"])
58
+ s.add_dependency(%q<minitest>, [">= 0"])
59
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ end
63
+ end
64
+
data/test/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'minitest/autorun'
11
+ require 'minitest/pride'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'sidekiq_metered_exceptions'
16
+
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ class TestSidekiqMeteredExceptions < Minitest::Test
4
+ describe 'middleware' do
5
+ before do
6
+ @middleware = SidekiqMeteredExceptions::Middleware.new
7
+ end
8
+
9
+ it 'should propagate exception if there is no retry count' do
10
+ assert_raises(Exception) { @middleware.call('worker', {}, 'queue') { raise Exception.new }}
11
+ end
12
+
13
+ it 'should propagate the exception if the retry count is greater than zero' do
14
+ assert_raises(Exception) { @middleware.call('worker', {'retry_count' => 1}, 'queue') { raise Exception.new }}
15
+ end
16
+
17
+ it 'should not propagate exception if the retry count is zero' do
18
+ @middleware.call('worker', {'retry_count' => 0}, 'queue') { raise Exception.new }
19
+ end
20
+
21
+ it "should not interfere with successful jobs" do
22
+ assert( @middleware.call('worker', {'retry_count' =>1}, 'queue') { return true })
23
+ end
24
+
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq_metered_exceptions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan Woodhull
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sidekiq
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.2.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.4
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.4
94
+ description: Some exceptions are transient, so notifying an admin is not useful.
95
+ email: woodhull@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.rdoc
101
+ files:
102
+ - .document
103
+ - .rvmrc
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ - Rakefile
109
+ - VERSION
110
+ - lib/middleware.rb
111
+ - lib/sidekiq_metered_exceptions.rb
112
+ - sidekiq_metered_exceptions.gemspec
113
+ - test/helper.rb
114
+ - test/test_sidekiq_metered_exceptions.rb
115
+ homepage: http://github.com/woodhull/sidekiq_metered_exceptions
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -37007965804888072
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.24
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Only propagate sidekiq exceptions that have already been retried once.
143
+ test_files: []