sidekiq 4.2.4 → 5.2.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq might be problematic. Click here for more details.

Files changed (108) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +61 -0
  3. data/.github/issue_template.md +8 -1
  4. data/.gitignore +3 -0
  5. data/.travis.yml +5 -6
  6. data/5.0-Upgrade.md +56 -0
  7. data/COMM-LICENSE +12 -10
  8. data/Changes.md +220 -0
  9. data/Ent-Changes.md +94 -2
  10. data/Gemfile +12 -22
  11. data/LICENSE +1 -1
  12. data/Pro-4.0-Upgrade.md +35 -0
  13. data/Pro-Changes.md +176 -2
  14. data/README.md +10 -7
  15. data/Rakefile +3 -3
  16. data/bin/sidekiqctl +13 -92
  17. data/bin/sidekiqload +16 -34
  18. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +1 -1
  19. data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
  20. data/lib/sidekiq/api.rb +166 -68
  21. data/lib/sidekiq/cli.rb +122 -77
  22. data/lib/sidekiq/client.rb +25 -18
  23. data/lib/sidekiq/core_ext.rb +1 -106
  24. data/lib/sidekiq/ctl.rb +221 -0
  25. data/lib/sidekiq/delay.rb +42 -0
  26. data/lib/sidekiq/exception_handler.rb +2 -4
  27. data/lib/sidekiq/extensions/generic_proxy.rb +7 -1
  28. data/lib/sidekiq/fetch.rb +1 -1
  29. data/lib/sidekiq/job_logger.rb +25 -0
  30. data/lib/sidekiq/job_retry.rb +262 -0
  31. data/lib/sidekiq/launcher.rb +49 -40
  32. data/lib/sidekiq/logging.rb +18 -2
  33. data/lib/sidekiq/manager.rb +6 -7
  34. data/lib/sidekiq/middleware/server/active_record.rb +10 -0
  35. data/lib/sidekiq/processor.rb +127 -37
  36. data/lib/sidekiq/rails.rb +16 -51
  37. data/lib/sidekiq/redis_connection.rb +50 -5
  38. data/lib/sidekiq/scheduled.rb +35 -8
  39. data/lib/sidekiq/testing.rb +24 -7
  40. data/lib/sidekiq/util.rb +6 -2
  41. data/lib/sidekiq/version.rb +1 -1
  42. data/lib/sidekiq/web/action.rb +3 -7
  43. data/lib/sidekiq/web/application.rb +38 -22
  44. data/lib/sidekiq/web/helpers.rb +78 -27
  45. data/lib/sidekiq/web/router.rb +14 -10
  46. data/lib/sidekiq/web.rb +4 -4
  47. data/lib/sidekiq/worker.rb +118 -19
  48. data/lib/sidekiq.rb +27 -26
  49. data/sidekiq.gemspec +8 -13
  50. data/web/assets/javascripts/application.js +0 -0
  51. data/web/assets/javascripts/dashboard.js +33 -18
  52. data/web/assets/stylesheets/application-rtl.css +246 -0
  53. data/web/assets/stylesheets/application.css +371 -6
  54. data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
  55. data/web/assets/stylesheets/bootstrap.css +2 -2
  56. data/web/locales/ar.yml +81 -0
  57. data/web/locales/en.yml +2 -0
  58. data/web/locales/es.yml +4 -3
  59. data/web/locales/fa.yml +80 -0
  60. data/web/locales/he.yml +79 -0
  61. data/web/locales/ja.yml +5 -3
  62. data/web/locales/ur.yml +80 -0
  63. data/web/views/_footer.erb +5 -2
  64. data/web/views/_job_info.erb +1 -1
  65. data/web/views/_nav.erb +4 -18
  66. data/web/views/_paging.erb +1 -1
  67. data/web/views/busy.erb +9 -5
  68. data/web/views/dashboard.erb +3 -3
  69. data/web/views/layout.erb +11 -2
  70. data/web/views/morgue.erb +14 -10
  71. data/web/views/queue.erb +11 -10
  72. data/web/views/queues.erb +4 -2
  73. data/web/views/retries.erb +17 -11
  74. data/web/views/retry.erb +1 -1
  75. data/web/views/scheduled.erb +2 -2
  76. metadata +32 -151
  77. data/lib/sidekiq/middleware/server/logging.rb +0 -40
  78. data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -205
  79. data/test/config.yml +0 -9
  80. data/test/env_based_config.yml +0 -11
  81. data/test/fake_env.rb +0 -1
  82. data/test/fixtures/en.yml +0 -2
  83. data/test/helper.rb +0 -75
  84. data/test/test_actors.rb +0 -138
  85. data/test/test_api.rb +0 -528
  86. data/test/test_cli.rb +0 -418
  87. data/test/test_client.rb +0 -266
  88. data/test/test_exception_handler.rb +0 -56
  89. data/test/test_extensions.rb +0 -127
  90. data/test/test_fetch.rb +0 -50
  91. data/test/test_launcher.rb +0 -95
  92. data/test/test_logging.rb +0 -35
  93. data/test/test_manager.rb +0 -50
  94. data/test/test_middleware.rb +0 -158
  95. data/test/test_processor.rb +0 -235
  96. data/test/test_rails.rb +0 -22
  97. data/test/test_redis_connection.rb +0 -132
  98. data/test/test_retry.rb +0 -326
  99. data/test/test_retry_exhausted.rb +0 -149
  100. data/test/test_scheduled.rb +0 -115
  101. data/test/test_scheduling.rb +0 -58
  102. data/test/test_sidekiq.rb +0 -107
  103. data/test/test_testing.rb +0 -143
  104. data/test/test_testing_fake.rb +0 -357
  105. data/test/test_testing_inline.rb +0 -94
  106. data/test/test_util.rb +0 -13
  107. data/test/test_web.rb +0 -726
  108. data/test/test_web_helpers.rb +0 -54
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.4
4
+ version: 5.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-01 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
20
- - - ">="
19
+ version: '4.5'
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.1
22
+ version: 4.6.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '3.2'
30
- - - ">="
29
+ version: '4.5'
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 3.2.1
32
+ version: 4.6.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: connection_pool
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '2.2'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 2.2.0
42
+ version: 2.2.2
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,21 +49,21 @@ dependencies:
49
49
  version: '2.2'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 2.2.0
52
+ version: 2.2.2
53
53
  - !ruby/object:Gem::Dependency
54
- name: concurrent-ruby
54
+ name: rack
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.0'
59
+ version: '2.0'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '1.0'
66
+ version: '2.0'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rack-protection
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -78,74 +78,6 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 1.5.0
81
- - !ruby/object:Gem::Dependency
82
- name: redis-namespace
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '1.5'
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: 1.5.2
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '1.5'
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: 1.5.2
101
- - !ruby/object:Gem::Dependency
102
- name: minitest
103
- requirement: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - "~>"
106
- - !ruby/object:Gem::Version
107
- version: '5.7'
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 5.7.0
111
- type: :development
112
- prerelease: false
113
- version_requirements: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '5.7'
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: 5.7.0
121
- - !ruby/object:Gem::Dependency
122
- name: rake
123
- requirement: !ruby/object:Gem::Requirement
124
- requirements:
125
- - - "~>"
126
- - !ruby/object:Gem::Version
127
- version: '10.0'
128
- type: :development
129
- prerelease: false
130
- version_requirements: !ruby/object:Gem::Requirement
131
- requirements:
132
- - - "~>"
133
- - !ruby/object:Gem::Version
134
- version: '10.0'
135
- - !ruby/object:Gem::Dependency
136
- name: rails
137
- requirement: !ruby/object:Gem::Requirement
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- version: 3.2.0
142
- type: :development
143
- prerelease: false
144
- version_requirements: !ruby/object:Gem::Requirement
145
- requirements:
146
- - - ">="
147
- - !ruby/object:Gem::Version
148
- version: 3.2.0
149
81
  description: Simple, efficient background processing for Ruby.
150
82
  email:
151
83
  - mperham@gmail.com
@@ -155,12 +87,14 @@ executables:
155
87
  extensions: []
156
88
  extra_rdoc_files: []
157
89
  files:
90
+ - ".circleci/config.yml"
158
91
  - ".github/contributing.md"
159
92
  - ".github/issue_template.md"
160
93
  - ".gitignore"
161
94
  - ".travis.yml"
162
95
  - 3.0-Upgrade.md
163
96
  - 4.0-Upgrade.md
97
+ - 5.0-Upgrade.md
164
98
  - COMM-LICENSE
165
99
  - Changes.md
166
100
  - Ent-Changes.md
@@ -168,6 +102,7 @@ files:
168
102
  - LICENSE
169
103
  - Pro-2.0-Upgrade.md
170
104
  - Pro-3.0-Upgrade.md
105
+ - Pro-4.0-Upgrade.md
171
106
  - Pro-Changes.md
172
107
  - README.md
173
108
  - Rakefile
@@ -184,20 +119,22 @@ files:
184
119
  - lib/sidekiq/cli.rb
185
120
  - lib/sidekiq/client.rb
186
121
  - lib/sidekiq/core_ext.rb
122
+ - lib/sidekiq/ctl.rb
123
+ - lib/sidekiq/delay.rb
187
124
  - lib/sidekiq/exception_handler.rb
188
125
  - lib/sidekiq/extensions/action_mailer.rb
189
126
  - lib/sidekiq/extensions/active_record.rb
190
127
  - lib/sidekiq/extensions/class_methods.rb
191
128
  - lib/sidekiq/extensions/generic_proxy.rb
192
129
  - lib/sidekiq/fetch.rb
130
+ - lib/sidekiq/job_logger.rb
131
+ - lib/sidekiq/job_retry.rb
193
132
  - lib/sidekiq/launcher.rb
194
133
  - lib/sidekiq/logging.rb
195
134
  - lib/sidekiq/manager.rb
196
135
  - lib/sidekiq/middleware/chain.rb
197
136
  - lib/sidekiq/middleware/i18n.rb
198
137
  - lib/sidekiq/middleware/server/active_record.rb
199
- - lib/sidekiq/middleware/server/logging.rb
200
- - lib/sidekiq/middleware/server/retry_jobs.rb
201
138
  - lib/sidekiq/paginator.rb
202
139
  - lib/sidekiq/processor.rb
203
140
  - lib/sidekiq/rails.rb
@@ -214,50 +151,25 @@ files:
214
151
  - lib/sidekiq/web/router.rb
215
152
  - lib/sidekiq/worker.rb
216
153
  - sidekiq.gemspec
217
- - test/config.yml
218
- - test/env_based_config.yml
219
- - test/fake_env.rb
220
- - test/fixtures/en.yml
221
- - test/helper.rb
222
- - test/test_actors.rb
223
- - test/test_api.rb
224
- - test/test_cli.rb
225
- - test/test_client.rb
226
- - test/test_exception_handler.rb
227
- - test/test_extensions.rb
228
- - test/test_fetch.rb
229
- - test/test_launcher.rb
230
- - test/test_logging.rb
231
- - test/test_manager.rb
232
- - test/test_middleware.rb
233
- - test/test_processor.rb
234
- - test/test_rails.rb
235
- - test/test_redis_connection.rb
236
- - test/test_retry.rb
237
- - test/test_retry_exhausted.rb
238
- - test/test_scheduled.rb
239
- - test/test_scheduling.rb
240
- - test/test_sidekiq.rb
241
- - test/test_testing.rb
242
- - test/test_testing_fake.rb
243
- - test/test_testing_inline.rb
244
- - test/test_util.rb
245
- - test/test_web.rb
246
- - test/test_web_helpers.rb
247
154
  - web/assets/images/favicon.ico
248
155
  - web/assets/images/logo.png
249
156
  - web/assets/images/status.png
250
157
  - web/assets/javascripts/application.js
251
158
  - web/assets/javascripts/dashboard.js
159
+ - web/assets/stylesheets/application-rtl.css
252
160
  - web/assets/stylesheets/application.css
161
+ - web/assets/stylesheets/bootstrap-rtl.min.css
253
162
  - web/assets/stylesheets/bootstrap.css
163
+ - web/locales/ar.yml
254
164
  - web/locales/cs.yml
255
165
  - web/locales/da.yml
256
166
  - web/locales/de.yml
257
167
  - web/locales/el.yml
258
168
  - web/locales/en.yml
259
169
  - web/locales/es.yml
170
+ - web/locales/fa.yml
260
171
  - web/locales/fr.yml
172
+ - web/locales/he.yml
261
173
  - web/locales/hi.yml
262
174
  - web/locales/it.yml
263
175
  - web/locales/ja.yml
@@ -271,6 +183,7 @@ files:
271
183
  - web/locales/sv.yml
272
184
  - web/locales/ta.yml
273
185
  - web/locales/uk.yml
186
+ - web/locales/ur.yml
274
187
  - web/locales/zh-cn.yml
275
188
  - web/locales/zh-tw.yml
276
189
  - web/views/_footer.erb
@@ -295,7 +208,7 @@ homepage: http://sidekiq.org
295
208
  licenses:
296
209
  - LGPL-3.0
297
210
  metadata: {}
298
- post_install_message:
211
+ post_install_message:
299
212
  rdoc_options: []
300
213
  require_paths:
301
214
  - lib
@@ -303,47 +216,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
216
  requirements:
304
217
  - - ">="
305
218
  - !ruby/object:Gem::Version
306
- version: '0'
219
+ version: 2.2.2
307
220
  required_rubygems_version: !ruby/object:Gem::Requirement
308
221
  requirements:
309
222
  - - ">="
310
223
  - !ruby/object:Gem::Version
311
224
  version: '0'
312
225
  requirements: []
313
- rubyforge_project:
314
- rubygems_version: 2.5.1
315
- signing_key:
226
+ rubygems_version: 3.2.32
227
+ signing_key:
316
228
  specification_version: 4
317
229
  summary: Simple, efficient background processing for Ruby
318
- test_files:
319
- - test/config.yml
320
- - test/env_based_config.yml
321
- - test/fake_env.rb
322
- - test/fixtures/en.yml
323
- - test/helper.rb
324
- - test/test_actors.rb
325
- - test/test_api.rb
326
- - test/test_cli.rb
327
- - test/test_client.rb
328
- - test/test_exception_handler.rb
329
- - test/test_extensions.rb
330
- - test/test_fetch.rb
331
- - test/test_launcher.rb
332
- - test/test_logging.rb
333
- - test/test_manager.rb
334
- - test/test_middleware.rb
335
- - test/test_processor.rb
336
- - test/test_rails.rb
337
- - test/test_redis_connection.rb
338
- - test/test_retry.rb
339
- - test/test_retry_exhausted.rb
340
- - test/test_scheduled.rb
341
- - test/test_scheduling.rb
342
- - test/test_sidekiq.rb
343
- - test/test_testing.rb
344
- - test/test_testing_fake.rb
345
- - test/test_testing_inline.rb
346
- - test/test_util.rb
347
- - test/test_web.rb
348
- - test/test_web_helpers.rb
349
- has_rdoc:
230
+ test_files: []
@@ -1,40 +0,0 @@
1
- module Sidekiq
2
- module Middleware
3
- module Server
4
- class Logging
5
-
6
- def call(worker, item, queue)
7
- Sidekiq::Logging.with_context(log_context(worker, item)) do
8
- begin
9
- start = Time.now
10
- logger.info("start".freeze)
11
- yield
12
- logger.info("done: #{elapsed(start)} sec")
13
- rescue Exception
14
- logger.info("fail: #{elapsed(start)} sec")
15
- raise
16
- end
17
- end
18
- end
19
-
20
- private
21
-
22
- # If we're using a wrapper class, like ActiveJob, use the "wrapped"
23
- # attribute to expose the underlying thing.
24
- def log_context(worker, item)
25
- klass = item['wrapped'.freeze] || worker.class.to_s
26
- "#{klass} JID-#{item['jid'.freeze]}#{" BID-#{item['bid'.freeze]}" if item['bid'.freeze]}"
27
- end
28
-
29
- def elapsed(start)
30
- (Time.now - start).round(3)
31
- end
32
-
33
- def logger
34
- Sidekiq.logger
35
- end
36
- end
37
- end
38
- end
39
- end
40
-
@@ -1,205 +0,0 @@
1
- require 'sidekiq/scheduled'
2
- require 'sidekiq/api'
3
-
4
- module Sidekiq
5
- module Middleware
6
- module Server
7
- ##
8
- # Automatically retry jobs that fail in Sidekiq.
9
- # Sidekiq's retry support assumes a typical development lifecycle:
10
- #
11
- # 0. Push some code changes with a bug in it.
12
- # 1. Bug causes job processing to fail, Sidekiq's middleware captures
13
- # the job and pushes it onto a retry queue.
14
- # 2. Sidekiq retries jobs in the retry queue multiple times with
15
- # an exponential delay, the job continues to fail.
16
- # 3. After a few days, a developer deploys a fix. The job is
17
- # reprocessed successfully.
18
- # 4. Once retries are exhausted, Sidekiq will give up and move the
19
- # job to the Dead Job Queue (aka morgue) where it must be dealt with
20
- # manually in the Web UI.
21
- # 5. After 6 months on the DJQ, Sidekiq will discard the job.
22
- #
23
- # A job looks like:
24
- #
25
- # { 'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => true }
26
- #
27
- # The 'retry' option also accepts a number (in place of 'true'):
28
- #
29
- # { 'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => 5 }
30
- #
31
- # The job will be retried this number of times before giving up. (If simply
32
- # 'true', Sidekiq retries 25 times)
33
- #
34
- # We'll add a bit more data to the job to support retries:
35
- #
36
- # * 'queue' - the queue to use
37
- # * 'retry_count' - number of times we've retried so far.
38
- # * 'error_message' - the message from the exception
39
- # * 'error_class' - the exception class
40
- # * 'failed_at' - the first time it failed
41
- # * 'retried_at' - the last time it was retried
42
- # * 'backtrace' - the number of lines of error backtrace to store
43
- #
44
- # We don't store the backtrace by default as that can add a lot of overhead
45
- # to the job and everyone is using an error service, right?
46
- #
47
- # The default number of retry attempts is 25 which works out to about 3 weeks
48
- # of retries. You can pass a value for the max number of retry attempts when
49
- # adding the middleware using the options hash:
50
- #
51
- # Sidekiq.configure_server do |config|
52
- # config.server_middleware do |chain|
53
- # chain.add Sidekiq::Middleware::Server::RetryJobs, :max_retries => 7
54
- # end
55
- # end
56
- #
57
- # or limit the number of retries for a particular worker with:
58
- #
59
- # class MyWorker
60
- # include Sidekiq::Worker
61
- # sidekiq_options :retry => 10
62
- # end
63
- #
64
- class RetryJobs
65
- include Sidekiq::Util
66
-
67
- DEFAULT_MAX_RETRY_ATTEMPTS = 25
68
-
69
- def initialize(options = {})
70
- @max_retries = options.fetch(:max_retries, DEFAULT_MAX_RETRY_ATTEMPTS)
71
- end
72
-
73
- def call(worker, msg, queue)
74
- yield
75
- rescue Sidekiq::Shutdown
76
- # ignore, will be pushed back onto queue during hard_shutdown
77
- raise
78
- rescue Exception => e
79
- # ignore, will be pushed back onto queue during hard_shutdown
80
- raise Sidekiq::Shutdown if exception_caused_by_shutdown?(e)
81
-
82
- raise e unless msg['retry']
83
- attempt_retry(worker, msg, queue, e)
84
- end
85
-
86
- private
87
-
88
- def attempt_retry(worker, msg, queue, exception)
89
- max_retry_attempts = retry_attempts_from(msg['retry'], @max_retries)
90
-
91
- msg['queue'] = if msg['retry_queue']
92
- msg['retry_queue']
93
- else
94
- queue
95
- end
96
-
97
- # App code can stuff all sorts of crazy binary data into the error message
98
- # that won't convert to JSON.
99
- m = exception.message.to_s[0, 10_000]
100
- if m.respond_to?(:scrub!)
101
- m.force_encoding("utf-8")
102
- m.scrub!
103
- end
104
-
105
- msg['error_message'] = m
106
- msg['error_class'] = exception.class.name
107
- count = if msg['retry_count']
108
- msg['retried_at'] = Time.now.to_f
109
- msg['retry_count'] += 1
110
- else
111
- msg['failed_at'] = Time.now.to_f
112
- msg['retry_count'] = 0
113
- end
114
-
115
- if msg['backtrace'] == true
116
- msg['error_backtrace'] = exception.backtrace
117
- elsif !msg['backtrace']
118
- # do nothing
119
- elsif msg['backtrace'].to_i != 0
120
- msg['error_backtrace'] = exception.backtrace[0...msg['backtrace'].to_i]
121
- end
122
-
123
- if count < max_retry_attempts
124
- delay = delay_for(worker, count, exception)
125
- logger.debug { "Failure! Retry #{count} in #{delay} seconds" }
126
- retry_at = Time.now.to_f + delay
127
- payload = Sidekiq.dump_json(msg)
128
- Sidekiq.redis do |conn|
129
- conn.zadd('retry', retry_at.to_s, payload)
130
- end
131
- else
132
- # Goodbye dear message, you (re)tried your best I'm sure.
133
- retries_exhausted(worker, msg, exception)
134
- end
135
-
136
- raise exception
137
- end
138
-
139
- def retries_exhausted(worker, msg, exception)
140
- logger.debug { "Retries exhausted for job" }
141
- begin
142
- block = worker.sidekiq_retries_exhausted_block || Sidekiq.default_retries_exhausted
143
- block.call(msg, exception) if block
144
- rescue => e
145
- handle_exception(e, { context: "Error calling retries_exhausted for #{worker.class}", job: msg })
146
- end
147
-
148
- send_to_morgue(msg) unless msg['dead'] == false
149
- end
150
-
151
- def send_to_morgue(msg)
152
- Sidekiq.logger.info { "Adding dead #{msg['class']} job #{msg['jid']}" }
153
- payload = Sidekiq.dump_json(msg)
154
- now = Time.now.to_f
155
- Sidekiq.redis do |conn|
156
- conn.multi do
157
- conn.zadd('dead', now, payload)
158
- conn.zremrangebyscore('dead', '-inf', now - DeadSet.timeout)
159
- conn.zremrangebyrank('dead', 0, -DeadSet.max_jobs)
160
- end
161
- end
162
- end
163
-
164
- def retry_attempts_from(msg_retry, default)
165
- if msg_retry.is_a?(Fixnum)
166
- msg_retry
167
- else
168
- default
169
- end
170
- end
171
-
172
- def delay_for(worker, count, exception)
173
- worker.sidekiq_retry_in_block? && retry_in(worker, count, exception) || seconds_to_delay(count)
174
- end
175
-
176
- # delayed_job uses the same basic formula
177
- def seconds_to_delay(count)
178
- (count ** 4) + 15 + (rand(30)*(count+1))
179
- end
180
-
181
- def retry_in(worker, count, exception)
182
- begin
183
- worker.sidekiq_retry_in_block.call(count, exception).to_i
184
- rescue Exception => e
185
- handle_exception(e, { context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{worker.class.name}, falling back to default" })
186
- nil
187
- end
188
- end
189
-
190
- def exception_caused_by_shutdown?(e, checked_causes = [])
191
- # In Ruby 2.1.0 only, check if exception is a result of shutdown.
192
- return false unless defined?(e.cause)
193
-
194
- # Handle circular causes
195
- checked_causes << e.object_id
196
- return false if checked_causes.include?(e.cause.object_id)
197
-
198
- e.cause.instance_of?(Sidekiq::Shutdown) ||
199
- exception_caused_by_shutdown?(e.cause, checked_causes)
200
- end
201
-
202
- end
203
- end
204
- end
205
- end
data/test/config.yml DELETED
@@ -1,9 +0,0 @@
1
- ---
2
- :verbose: false
3
- :require: ./test/fake_env.rb
4
- :pidfile: /tmp/sidekiq-config-test.pid
5
- :logfile: /tmp/sidekiq.log
6
- :concurrency: 50
7
- :queues:
8
- - [<%="very_"%>often, 2]
9
- - [seldom, 1]
@@ -1,11 +0,0 @@
1
- ---
2
- :pidfile: /tmp/sidekiq-config-test.pid
3
- :concurrency: 50
4
- staging:
5
- :verbose: false
6
- :require: ./test/fake_env.rb
7
- :logfile: /tmp/sidekiq.log
8
- :concurrency: 5
9
- :queues:
10
- - [<%="very_"%>often, 2]
11
- - [seldom, 1]
data/test/fake_env.rb DELETED
@@ -1 +0,0 @@
1
- # frozen_string_literal: true
data/test/fixtures/en.yml DELETED
@@ -1,2 +0,0 @@
1
- en:
2
- translated_text: 'Changed text from add locals'
data/test/helper.rb DELETED
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
- $TESTING = true
3
- # disable minitest/parallel threads
4
- ENV["N"] = "0"
5
-
6
- if ENV["COVERAGE"]
7
- require 'simplecov'
8
- SimpleCov.start do
9
- add_filter "/test/"
10
- add_filter "/myapp/"
11
- end
12
- end
13
- ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
14
-
15
- trap 'USR1' do
16
- threads = Thread.list
17
-
18
- puts
19
- puts "=" * 80
20
- puts "Received USR1 signal; printing all #{threads.count} thread backtraces."
21
-
22
- threads.each do |thr|
23
- description = thr == Thread.main ? "Main thread" : thr.inspect
24
- puts
25
- puts "#{description} backtrace: "
26
- puts thr.backtrace.join("\n")
27
- end
28
-
29
- puts "=" * 80
30
- end
31
-
32
- begin
33
- require 'pry-byebug'
34
- rescue LoadError
35
- end
36
-
37
- require 'minitest/autorun'
38
-
39
- require 'sidekiq'
40
- require 'sidekiq/util'
41
- Sidekiq.logger.level = Logger::ERROR
42
-
43
- Sidekiq::Test = Minitest::Test
44
-
45
- require 'sidekiq/redis_connection'
46
- REDIS_URL = ENV['REDIS_URL'] || 'redis://localhost/15'
47
- REDIS = Sidekiq::RedisConnection.create(:url => REDIS_URL, :namespace => 'testy')
48
-
49
- Sidekiq.configure_client do |config|
50
- config.redis = { :url => REDIS_URL, :namespace => 'testy' }
51
- end
52
-
53
- def capture_logging(lvl=Logger::INFO)
54
- old = Sidekiq.logger
55
- begin
56
- out = StringIO.new
57
- logger = Logger.new(out)
58
- logger.level = lvl
59
- Sidekiq.logger = logger
60
- yield
61
- out.string
62
- ensure
63
- Sidekiq.logger = old
64
- end
65
- end
66
-
67
- def with_logging(lvl=Logger::DEBUG)
68
- old = Sidekiq.logger.level
69
- begin
70
- Sidekiq.logger.level = lvl
71
- yield
72
- ensure
73
- Sidekiq.logger.level = old
74
- end
75
- end