sidekiq-failures 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +12 -0
- data/lib/sidekiq-failures.rb +1 -0
- data/lib/sidekiq/failures.rb +17 -0
- data/lib/sidekiq/failures/middleware.rb +23 -0
- data/lib/sidekiq/failures/version.rb +5 -0
- data/lib/sidekiq/failures/views/failures.slim +26 -0
- data/lib/sidekiq/failures/web_extension.rb +24 -0
- data/sidekiq-failures.gemspec +25 -0
- data/test/middleware_test.rb +41 -0
- data/test/test_helper.rb +13 -0
- data/test/web_extension_test.rb +54 -0
- metadata +163 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Marcelo Silveira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Sidekiq::Failures
|
2
|
+
|
3
|
+
Keeps track of Sidekiq failed jobs and adds a tab to the Web UI to let you browse
|
4
|
+
them. Makes use of Sidekiq's custom tabs and middleware chain.
|
5
|
+
|
6
|
+
It mimics the way Resque keeps track of failures.
|
7
|
+
|
8
|
+
Note that each failed retry will create a new failed job. This might result in a
|
9
|
+
pretty big failures list. Think twice before using this project. In most cases
|
10
|
+
automatic retries allied to exception notifications will be enough.
|
11
|
+
|
12
|
+
## Important Note!
|
13
|
+
|
14
|
+
This is an ongoing, alpha level project. Be prepared that the API might change and bugs might occur.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'sidekiq-failures'
|
22
|
+
```
|
23
|
+
|
24
|
+
## Dependencies
|
25
|
+
|
26
|
+
Depends on Sidekiq >= 2.2.1
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Simply having the gem in your Gemfile should be enough.
|
31
|
+
|
32
|
+
Your failed jobs will be visible via a Failures tab in the Web UI.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
Released under the MIT License. See the [LICENSE][license] file for further details.
|
45
|
+
|
46
|
+
[license]: https://github.com/mhfs/sidekiq-failures/blob/master/LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "sidekiq/failures"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "sidekiq/web"
|
2
|
+
require "sidekiq/processor"
|
3
|
+
require "sidekiq/failures/version"
|
4
|
+
require "sidekiq/failures/middleware"
|
5
|
+
require "sidekiq/failures/web_extension"
|
6
|
+
|
7
|
+
module Sidekiq
|
8
|
+
module Failures
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Sidekiq::Web.register Sidekiq::Failures::WebExtension
|
13
|
+
Sidekiq::Web.tabs << "Failures"
|
14
|
+
|
15
|
+
Sidekiq.server_middleware do |chain|
|
16
|
+
chain.add Sidekiq::Failures::Middleware
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Failures
|
3
|
+
class Middleware
|
4
|
+
def call(worker, msg, queue)
|
5
|
+
yield
|
6
|
+
rescue => e
|
7
|
+
data = {
|
8
|
+
:failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S %Z"),
|
9
|
+
:payload => msg,
|
10
|
+
:exception => e.class.to_s,
|
11
|
+
:error => e.to_s,
|
12
|
+
:backtrace => e.backtrace,
|
13
|
+
:worker => msg['class'],
|
14
|
+
:queue => queue
|
15
|
+
}
|
16
|
+
|
17
|
+
Sidekiq.redis { |conn| conn.rpush(:failed, Sidekiq.dump_json(data)) }
|
18
|
+
|
19
|
+
raise
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
h1 Failed Jobs
|
2
|
+
|
3
|
+
- if @messages.size > 0
|
4
|
+
== slim :_paging, :locals => { :url => "#{root_path}queues/#{@name}" }
|
5
|
+
|
6
|
+
table class="table table-striped table-bordered"
|
7
|
+
tr
|
8
|
+
th Worker
|
9
|
+
th Args
|
10
|
+
th Queue
|
11
|
+
th Exception
|
12
|
+
th Error
|
13
|
+
th Failed At
|
14
|
+
- @messages.each do |msg|
|
15
|
+
tr
|
16
|
+
td= msg['worker']
|
17
|
+
td= msg['payload']['args'].inspect[0..100]
|
18
|
+
td= msg['queue']
|
19
|
+
td= msg['exception']
|
20
|
+
td= msg['error']
|
21
|
+
td= msg['failed_at']
|
22
|
+
|
23
|
+
== slim :_paging, :locals => { :url => "#{root_path}queues/#{@name}" }
|
24
|
+
- else
|
25
|
+
p No failed jobs found.
|
26
|
+
a href="#{root_path}" Back
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Failures
|
3
|
+
module WebExtension
|
4
|
+
|
5
|
+
def self.registered(app)
|
6
|
+
app.helpers do
|
7
|
+
def find_template(view, *a, &b)
|
8
|
+
dir = File.expand_path("../views/", __FILE__)
|
9
|
+
super(dir, *a, &b)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
app.get "/failures" do
|
15
|
+
@count = (params[:count] || 25).to_i
|
16
|
+
(@current_page, @total_size, @messages) = page("failed", params[:page], @count)
|
17
|
+
@messages = @messages.map { |msg| Sidekiq.load_json(msg) }
|
18
|
+
|
19
|
+
slim :failures
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sidekiq/failures/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Marcelo Silveira"]
|
6
|
+
gem.email = ["marcelo@mhfs.com.br"]
|
7
|
+
gem.description = %q{Keep track of Sidekiq failed jobs}
|
8
|
+
gem.summary = %q{Keeps track of Sidekiq failed jobs and adds a tab to the Web UI to let you browse them. Makes use of Sidekiq's custom tabs and middleware chain.}
|
9
|
+
gem.homepage = "https://github.com/mhfs/sidekiq-failures/"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "sidekiq-failures"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Sidekiq::Failures::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "sidekiq", ">= 2.2.1"
|
19
|
+
gem.add_dependency "slim"
|
20
|
+
gem.add_dependency "sinatra"
|
21
|
+
gem.add_dependency "sprockets"
|
22
|
+
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "rack-test"
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Failures
|
5
|
+
describe "Middleware" do
|
6
|
+
TestException = Class.new(StandardError)
|
7
|
+
|
8
|
+
before do
|
9
|
+
$invokes = 0
|
10
|
+
boss = MiniTest::Mock.new
|
11
|
+
@processor = ::Sidekiq::Processor.new(boss)
|
12
|
+
Sidekiq.redis = REDIS
|
13
|
+
Sidekiq.redis { |c| c.flushdb }
|
14
|
+
end
|
15
|
+
|
16
|
+
class MockWorker
|
17
|
+
include Sidekiq::Worker
|
18
|
+
sidekiq_options :retry => false
|
19
|
+
|
20
|
+
def perform(args)
|
21
|
+
$invokes += 1
|
22
|
+
raise TestException.new("failed!")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'record failures' do
|
27
|
+
msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
|
28
|
+
|
29
|
+
Sidekiq.redis { |conn| assert_equal 0, conn.llen('failed') || 0 }
|
30
|
+
|
31
|
+
assert_raises TestException do
|
32
|
+
@processor.process(msg, 'default')
|
33
|
+
end
|
34
|
+
|
35
|
+
Sidekiq.redis { |conn| assert_equal 1, conn.llen('failed') || 0 }
|
36
|
+
|
37
|
+
assert_equal 1, $invokes
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "minitest/spec"
|
3
|
+
require "minitest/mock"
|
4
|
+
|
5
|
+
require "rack/test"
|
6
|
+
|
7
|
+
require "sidekiq"
|
8
|
+
require "sidekiq-failures"
|
9
|
+
|
10
|
+
Celluloid.logger = nil
|
11
|
+
Sidekiq.logger.level = Logger::ERROR
|
12
|
+
|
13
|
+
REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'sidekiq_failures_test')
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
describe "WebExtension" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
Sidekiq::Web
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
Sidekiq.redis = REDIS
|
13
|
+
Sidekiq.redis {|c| c.flushdb }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can display home with failures tab' do
|
17
|
+
get '/'
|
18
|
+
|
19
|
+
last_response.status.must_equal 200
|
20
|
+
last_response.body.must_match /Sidekiq is idle/
|
21
|
+
last_response.body.must_match /Failures/
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can display failures page without any failures' do
|
25
|
+
get '/failures'
|
26
|
+
last_response.status.must_equal 200
|
27
|
+
last_response.body.must_match /Failed Jobs/
|
28
|
+
last_response.body.must_match /No failed jobs found/
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can display failures page with failures listed' do
|
32
|
+
create_sample_failure
|
33
|
+
get '/failures'
|
34
|
+
last_response.status.must_equal 200
|
35
|
+
last_response.body.must_match /HardWorker/
|
36
|
+
last_response.body.must_match /ArgumentError/
|
37
|
+
last_response.body.wont_match /No failed jobs found/
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_sample_failure
|
41
|
+
data = {
|
42
|
+
:failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S %Z"),
|
43
|
+
:payload => { :args => ["bob", 5] },
|
44
|
+
:exception => "ArgumentError",
|
45
|
+
:error => "Some new message",
|
46
|
+
:backtrace => ["path/file1.rb", "path/file2.rb"],
|
47
|
+
:worker => 'HardWorker',
|
48
|
+
:queue => 'default'
|
49
|
+
}
|
50
|
+
|
51
|
+
Sidekiq.redis { |conn| conn.rpush(:failed, Sidekiq.dump_json(data)) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-failures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marcelo Silveira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-24 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: 2.2.1
|
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: 2.2.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: slim
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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: sinatra
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sprockets
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
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: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack-test
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Keep track of Sidekiq failed jobs
|
111
|
+
email:
|
112
|
+
- marcelo@mhfs.com.br
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/sidekiq-failures.rb
|
123
|
+
- lib/sidekiq/failures.rb
|
124
|
+
- lib/sidekiq/failures/middleware.rb
|
125
|
+
- lib/sidekiq/failures/version.rb
|
126
|
+
- lib/sidekiq/failures/views/failures.slim
|
127
|
+
- lib/sidekiq/failures/web_extension.rb
|
128
|
+
- sidekiq-failures.gemspec
|
129
|
+
- test/middleware_test.rb
|
130
|
+
- test/test_helper.rb
|
131
|
+
- test/web_extension_test.rb
|
132
|
+
homepage: https://github.com/mhfs/sidekiq-failures/
|
133
|
+
licenses: []
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
hash: -3924324367283502437
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ! '>'
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.3.1
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 1.8.23
|
156
|
+
signing_key:
|
157
|
+
specification_version: 3
|
158
|
+
summary: Keeps track of Sidekiq failed jobs and adds a tab to the Web UI to let you
|
159
|
+
browse them. Makes use of Sidekiq's custom tabs and middleware chain.
|
160
|
+
test_files:
|
161
|
+
- test/middleware_test.rb
|
162
|
+
- test/test_helper.rb
|
163
|
+
- test/web_extension_test.rb
|