sidekiq-failures 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 708163dea57e9c34fbaf279980cd23c56420415f
4
+ data.tar.gz: 1a8967ec4c7efc057fa48e2481601fc42980edf0
5
+ SHA512:
6
+ metadata.gz: d8bca52118ae7b792ac8387c25aad0662680b2797ab8fe0bd0b668986fe4643f26ddefc2200d33cbf4c662a85d16d1279f2ff33097ebaa502eddbd1da5413beb
7
+ data.tar.gz: 5ac567f23aa5f0e9f27769ca5223da6c4d08f4e6de981c398c87e6a3978706d543302370539d413f9023a7c504e0015b200f641a76f433fbc1ca7c058242c2d8
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ services:
3
+ - redis-server
4
+ rvm:
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - 2.0.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.3.0
4
+ * Bump sidekiq dependency to sidekiq >= 2.14.0
5
+ * Remove slim templates and dependecy
6
+ * Escape exception info when outputing to html
7
+ * Add `Sidekiq::Failures.reset_failures` helper method
8
+ * Add `Sidekiq::Failures.count` helper method (@zanker)
9
+ * Adhere to sidekiq approach of showing UTC times
10
+ * Catch all exceptions, not just those that inherit from StandardError (@tylerkovacs)
11
+ * Fix pricate method call (@bwthomas)
12
+
3
13
  ## 0.2.2
4
14
  * Support ERB for sidekiq >= 2.14.0 (@tobiassvn)
5
15
  * Bump sidekiq dep to >= 2.9.0
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq-failures (0.2.2)
5
- sidekiq (>= 2.9.0)
4
+ sidekiq-failures (0.3.0)
5
+ sidekiq (>= 2.14.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- celluloid (0.14.1)
11
- timers (>= 1.0.0)
12
- connection_pool (1.1.0)
10
+ celluloid (0.15.2)
11
+ timers (~> 1.1.0)
12
+ connection_pool (1.2.0)
13
13
  hike (1.2.1)
14
- json (1.8.0)
14
+ json (1.8.1)
15
15
  multi_json (1.7.3)
16
16
  rack (1.4.1)
17
17
  rack-protection (1.2.0)
@@ -19,28 +19,24 @@ GEM
19
19
  rack-test (0.6.2)
20
20
  rack (>= 1.0)
21
21
  rake (0.9.2.2)
22
- redis (3.0.4)
23
- redis-namespace (1.3.1)
24
- redis (~> 3.0.0)
25
- sidekiq (2.13.0)
26
- celluloid (>= 0.14.1)
22
+ redis (3.0.6)
23
+ redis-namespace (1.3.2)
24
+ redis (~> 3.0.4)
25
+ sidekiq (2.17.0)
26
+ celluloid (>= 0.15.2)
27
27
  connection_pool (>= 1.0.0)
28
28
  json
29
- redis (>= 3.0)
30
- redis-namespace
29
+ redis (>= 3.0.4)
30
+ redis-namespace (>= 1.3.1)
31
31
  sinatra (1.3.3)
32
32
  rack (~> 1.3, >= 1.3.6)
33
33
  rack-protection (~> 1.2)
34
34
  tilt (~> 1.3, >= 1.3.3)
35
- slim (1.3.4)
36
- temple (~> 0.5.5)
37
- tilt (~> 1.3.3)
38
35
  sprockets (2.8.1)
39
36
  hike (~> 1.2)
40
37
  multi_json (~> 1.0)
41
38
  rack (~> 1.0)
42
39
  tilt (~> 1.1, != 1.3.0)
43
- temple (0.5.5)
44
40
  tilt (1.3.3)
45
41
  timers (1.1.0)
46
42
 
@@ -52,5 +48,4 @@ DEPENDENCIES
52
48
  rake
53
49
  sidekiq-failures!
54
50
  sinatra
55
- slim
56
51
  sprockets
data/README.md CHANGED
@@ -113,9 +113,30 @@ end
113
113
 
114
114
  The valid modes are `:all`, `:exhausted` or `:off`.
115
115
 
116
+ ## Helper Methods
117
+
118
+ ### Failures Count
119
+
120
+ Gives back the number of failed jobs currently stored in Sidekiq Failures. Notice that it's
121
+ different from `Sidekiq` built in failed stat. Also, notice that this might be
122
+ influenced by `failures_max_count`.
123
+
124
+ ```ruby
125
+ Sidekiq::Failures.count
126
+ ```
127
+
128
+ ### Reset Failures
129
+
130
+ Gives a convenient way of reseting Sidekiq Failure stored failed jobs programmatically.
131
+ Takes an options hash and if the `counter` key is present also resets Sidekiq own failed stats.
132
+
133
+ ```ruby
134
+ Sidekiq::Failures.reset_failures
135
+ ```
136
+
116
137
  ## Dependencies
117
138
 
118
- Depends on Sidekiq >= 2.9.0
139
+ Depends on Sidekiq >= 2.14.0
119
140
 
120
141
  ## Contributing
121
142
 
@@ -50,6 +50,21 @@ module Sidekiq
50
50
  end
51
51
 
52
52
  module Failures
53
+
54
+ LIST_KEY = :failed
55
+
56
+ def self.reset_failures(options = {})
57
+ Sidekiq.redis { |c|
58
+ c.multi do
59
+ c.del(LIST_KEY)
60
+ c.set("stat:failed", 0) if options[:counter] || options["counter"]
61
+ end
62
+ }
63
+ end
64
+
65
+ def self.count
66
+ Sidekiq.redis {|r| r.llen(LIST_KEY) }
67
+ end
53
68
  end
54
69
  end
55
70
 
@@ -10,11 +10,11 @@ module Sidekiq
10
10
  yield
11
11
  rescue Sidekiq::Shutdown
12
12
  raise
13
- rescue => e
13
+ rescue Exception => e
14
14
  raise e if skip_failure?
15
15
 
16
16
  data = {
17
- :failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S %Z"),
17
+ :failed_at => Time.now.utc,
18
18
  :payload => msg,
19
19
  :exception => e.class.to_s,
20
20
  :error => e.message,
@@ -25,9 +25,9 @@ module Sidekiq
25
25
  }
26
26
 
27
27
  Sidekiq.redis do |conn|
28
- conn.lpush(:failed, Sidekiq.dump_json(data))
28
+ conn.lpush(LIST_KEY, Sidekiq.dump_json(data))
29
29
  unless Sidekiq.failures_max_count == false
30
- conn.ltrim(:failed, 0, Sidekiq.failures_max_count - 1)
30
+ conn.ltrim(LIST_KEY, 0, Sidekiq.failures_max_count - 1)
31
31
  end
32
32
  end
33
33
 
@@ -66,7 +66,7 @@ module Sidekiq
66
66
  end
67
67
 
68
68
  def max_retries
69
- retry_middleware.retry_attempts_from(msg['retry'], default_max_retries)
69
+ retry_middleware.send(:retry_attempts_from, msg['retry'], default_max_retries)
70
70
  end
71
71
 
72
72
  def retry_middleware
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Failures
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -26,13 +26,11 @@
26
26
  </td>
27
27
  <td><%= msg['queue'] %></td>
28
28
  <td>
29
- <time datetime="<%= "#{Time.parse(msg['failed_at']).getutc.iso8601}" %>">
30
- <%= msg['failed_at'] %>
31
- </time>
29
+ <%= relative_time(Time.parse(msg['failed_at'])) %>
32
30
  </td>
33
31
  <td style="overflow: auto; padding: 10px;">
34
32
  <a class="backtrace" href="#" onclick="$(this).next().toggle(); return false">
35
- <%= msg['exception'] %>: <%= msg['error'] %>
33
+ <%= h msg['exception'] %>: <%= h msg['error'] %>
36
34
  </a>
37
35
  <pre style="display: none; background: none; border: 0; width: 100%; max-height: 30em; font-size: 0.8em; white-space: nowrap;">
38
36
  <%= msg['backtrace'].join("<br />") %>
@@ -10,20 +10,11 @@ module Sidekiq
10
10
  (@current_page, @total_size, @messages) = page("failed", params[:page], @count)
11
11
  @messages = @messages.map { |msg| Sidekiq.load_json(msg) }
12
12
 
13
- if Sidekiq::VERSION < "2.14.0"
14
- render(:slim, File.read(File.join(view_path, "failures.slim")))
15
- else
16
- render(:erb, File.read(File.join(view_path, "failures.erb")))
17
- end
13
+ render(:erb, File.read(File.join(view_path, "failures.erb")))
18
14
  end
19
15
 
20
16
  app.post "/failures/remove" do
21
- Sidekiq.redis {|c|
22
- c.multi do
23
- c.del("failed")
24
- c.set("stat:failed", 0) if params["counter"]
25
- end
26
- }
17
+ Sidekiq::Failures.reset_failures(counter: params["counter"])
27
18
 
28
19
  redirect "#{root_path}failures"
29
20
  end
@@ -15,11 +15,10 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Sidekiq::Failures::VERSION
17
17
 
18
- gem.add_dependency "sidekiq", ">= 2.9.0"
18
+ gem.add_dependency "sidekiq", ">= 2.14.0"
19
19
 
20
20
  gem.add_development_dependency "rake"
21
21
  gem.add_development_dependency "rack-test"
22
22
  gem.add_development_dependency "sprockets"
23
23
  gem.add_development_dependency "sinatra"
24
- gem.add_development_dependency "slim"
25
24
  end
@@ -4,6 +4,7 @@ module Sidekiq
4
4
  module Failures
5
5
  describe "Middleware" do
6
6
  before do
7
+ Celluloid.boot
7
8
  $invokes = 0
8
9
  @boss = MiniTest::Mock.new
9
10
  @processor = ::Sidekiq::Processor.new(@boss)
@@ -13,7 +14,7 @@ module Sidekiq
13
14
  Sidekiq.instance_eval { @failures_default_mode = nil }
14
15
  end
15
16
 
16
- TestException = Class.new(StandardError)
17
+ TestException = Class.new(Exception)
17
18
  ShutdownException = Class.new(Sidekiq::Shutdown)
18
19
 
19
20
  class MockWorker
@@ -177,11 +178,11 @@ module Sidekiq
177
178
  assert_raises TestException do
178
179
  @processor.process(msg)
179
180
  end
180
-
181
+
181
182
  assert_equal 1, failures_count
182
183
  assert_equal 1, $invokes
183
184
  end
184
-
185
+
185
186
  it "records failure if retry disabled and configured to track exhaustion by default" do
186
187
  Sidekiq.failures_default_mode = 'exhausted'
187
188
 
@@ -233,7 +234,7 @@ module Sidekiq
233
234
  3.times do
234
235
  boss = MiniTest::Mock.new
235
236
  processor = ::Sidekiq::Processor.new(boss)
236
-
237
+
237
238
  actor = MiniTest::Mock.new
238
239
  actor.expect(:processor_done, nil, [processor])
239
240
  actor.expect(:real_thread, nil, [nil, Celluloid::Thread])
@@ -253,6 +254,23 @@ module Sidekiq
253
254
  assert_equal 1000, Sidekiq.failures_max_count
254
255
  end
255
256
 
257
+ it 'returns the total number of failed jobs in the queue' do
258
+ msg = create_work('class' => MockWorker.to_s, 'args' => ['myarg'], 'failures' => true)
259
+
260
+ assert_equal 0, Sidekiq::Failures.count
261
+
262
+ actor = MiniTest::Mock.new
263
+ actor.expect(:processor_done, nil, [@processor])
264
+ actor.expect(:real_thread, nil, [nil, Celluloid::Thread])
265
+ @boss.expect(:async, actor, [])
266
+
267
+ assert_raises TestException do
268
+ @processor.process(msg)
269
+ end
270
+
271
+ assert_equal 1, Sidekiq::Failures.count
272
+ end
273
+
256
274
  def failures_count
257
275
  Sidekiq.redis { |conn|conn.llen('failed') } || 0
258
276
  end
data/test/test_helper.rb CHANGED
@@ -5,13 +5,6 @@ require "minitest/autorun"
5
5
  require "minitest/spec"
6
6
  require "minitest/mock"
7
7
 
8
- # FIXME Remove once https://github.com/mperham/sidekiq/pull/548 is released.
9
- class String
10
- def blank?
11
- self !~ /[^[:space:]]/
12
- end
13
- end
14
-
15
8
  require "rack/test"
16
9
 
17
10
  require "celluloid"
metadata CHANGED
@@ -1,110 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-failures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Marcelo Silveira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
11
+ date: 2013-12-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sidekiq
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: 2.9.0
19
+ version: 2.14.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: 2.9.0
26
+ version: 2.14.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rack-test
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sprockets
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: sinatra
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: slim
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
- - - ! '>='
80
+ - - '>='
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  description: Keep track of Sidekiq failed jobs
@@ -115,6 +88,7 @@ extensions: []
115
88
  extra_rdoc_files: []
116
89
  files:
117
90
  - .gitignore
91
+ - .travis.yml
118
92
  - CHANGELOG.md
119
93
  - Gemfile
120
94
  - Gemfile.lock
@@ -126,7 +100,6 @@ files:
126
100
  - lib/sidekiq/failures/middleware.rb
127
101
  - lib/sidekiq/failures/version.rb
128
102
  - lib/sidekiq/failures/views/failures.erb
129
- - lib/sidekiq/failures/views/failures.slim
130
103
  - lib/sidekiq/failures/web_extension.rb
131
104
  - sidekiq-failures.gemspec
132
105
  - test/middleware_test.rb
@@ -134,33 +107,26 @@ files:
134
107
  - test/web_extension_test.rb
135
108
  homepage: https://github.com/mhfs/sidekiq-failures/
136
109
  licenses: []
110
+ metadata: {}
137
111
  post_install_message:
138
112
  rdoc_options: []
139
113
  require_paths:
140
114
  - lib
141
115
  required_ruby_version: !ruby/object:Gem::Requirement
142
- none: false
143
116
  requirements:
144
- - - ! '>='
117
+ - - '>='
145
118
  - !ruby/object:Gem::Version
146
119
  version: '0'
147
- segments:
148
- - 0
149
- hash: -612683227478286431
150
120
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
121
  requirements:
153
- - - ! '>='
122
+ - - '>='
154
123
  - !ruby/object:Gem::Version
155
124
  version: '0'
156
- segments:
157
- - 0
158
- hash: -612683227478286431
159
125
  requirements: []
160
126
  rubyforge_project:
161
- rubygems_version: 1.8.23
127
+ rubygems_version: 2.0.3
162
128
  signing_key:
163
- specification_version: 3
129
+ specification_version: 4
164
130
  summary: Keeps track of Sidekiq failed jobs and adds a tab to the Web UI to let you
165
131
  browse them. Makes use of Sidekiq's custom tabs and middleware chain.
166
132
  test_files:
@@ -1,41 +0,0 @@
1
- header.row
2
- .span5
3
- h3 Failed Jobs
4
- .span4
5
- - if @messages.size > 0
6
- == slim :_paging, :locals => { :url => "#{root_path}failures#@name" }
7
-
8
- - if @messages.size > 0
9
- table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;"
10
- thead
11
- th style="width: 25%" Worker, Args
12
- th style="width: 10%" Queue
13
- th style="width: 15%" Failed At
14
- th style="width: 50%" Exception
15
- - @messages.each do |msg|
16
- tr
17
- td style="overflow: hidden; text-overflow: ellipsis;"
18
- = msg['worker']
19
- br
20
- = msg['payload']['args'].inspect[0..100]
21
- td= msg['queue']
22
- td
23
- time datetime="#{Time.parse(msg['failed_at']).getutc.iso8601}"
24
- = msg['failed_at']
25
- td style="overflow: auto; padding: 10px;"
26
- a.backtrace href="#" onclick="$(this).next().toggle(); return false" = "#{msg['exception']}: #{msg['error']}"
27
- pre style="display: none; background: none; border: 0; width: 100%; max-height: 30em; font-size: 0.8em; white-space: nowrap;" == msg['backtrace'].join("<br />")
28
- p
29
- span Processor: #{msg['processor']}
30
-
31
- div.row
32
- .span5
33
- form.form-inline action="#{root_path}failures/remove" method="post" style="margin: 20px 0"
34
- input.btn.btn-danger.btn-small type="submit" name="delete" value="Clear All"
35
- label class="checkbox"
36
- input type="checkbox" name="counter" value="true"
37
- = "reset failed counter"
38
- .span4
39
- == slim :_paging, :locals => { :url => "#{root_path}failures#@name" }
40
- - else
41
- .alert.alert-success No failed jobs found.