sidekiq 6.0.1 → 6.2.2

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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +147 -2
  3. data/LICENSE +1 -1
  4. data/README.md +4 -7
  5. data/bin/sidekiq +26 -2
  6. data/lib/generators/sidekiq/worker_generator.rb +1 -1
  7. data/lib/sidekiq/api.rb +151 -111
  8. data/lib/sidekiq/cli.rb +39 -10
  9. data/lib/sidekiq/client.rb +26 -15
  10. data/lib/sidekiq/extensions/action_mailer.rb +3 -2
  11. data/lib/sidekiq/extensions/active_record.rb +4 -3
  12. data/lib/sidekiq/extensions/class_methods.rb +5 -4
  13. data/lib/sidekiq/extensions/generic_proxy.rb +3 -1
  14. data/lib/sidekiq/fetch.rb +29 -21
  15. data/lib/sidekiq/job.rb +8 -0
  16. data/lib/sidekiq/job_logger.rb +2 -2
  17. data/lib/sidekiq/job_retry.rb +11 -12
  18. data/lib/sidekiq/launcher.rb +104 -24
  19. data/lib/sidekiq/logger.rb +12 -11
  20. data/lib/sidekiq/manager.rb +4 -4
  21. data/lib/sidekiq/middleware/chain.rb +6 -4
  22. data/lib/sidekiq/monitor.rb +2 -17
  23. data/lib/sidekiq/processor.rb +17 -39
  24. data/lib/sidekiq/rails.rb +16 -18
  25. data/lib/sidekiq/redis_connection.rb +21 -13
  26. data/lib/sidekiq/scheduled.rb +7 -1
  27. data/lib/sidekiq/sd_notify.rb +149 -0
  28. data/lib/sidekiq/systemd.rb +24 -0
  29. data/lib/sidekiq/testing.rb +2 -4
  30. data/lib/sidekiq/util.rb +28 -2
  31. data/lib/sidekiq/version.rb +1 -1
  32. data/lib/sidekiq/web/action.rb +2 -2
  33. data/lib/sidekiq/web/application.rb +30 -19
  34. data/lib/sidekiq/web/csrf_protection.rb +180 -0
  35. data/lib/sidekiq/web/helpers.rb +35 -24
  36. data/lib/sidekiq/web/router.rb +6 -5
  37. data/lib/sidekiq/web.rb +37 -73
  38. data/lib/sidekiq/worker.rb +4 -7
  39. data/lib/sidekiq.rb +14 -8
  40. data/sidekiq.gemspec +12 -5
  41. data/web/assets/images/apple-touch-icon.png +0 -0
  42. data/web/assets/javascripts/application.js +25 -27
  43. data/web/assets/stylesheets/application-dark.css +146 -124
  44. data/web/assets/stylesheets/application.css +35 -135
  45. data/web/locales/ar.yml +8 -2
  46. data/web/locales/de.yml +14 -2
  47. data/web/locales/en.yml +5 -0
  48. data/web/locales/es.yml +18 -2
  49. data/web/locales/fr.yml +10 -3
  50. data/web/locales/ja.yml +5 -0
  51. data/web/locales/lt.yml +83 -0
  52. data/web/locales/pl.yml +4 -4
  53. data/web/locales/ru.yml +4 -0
  54. data/web/locales/vi.yml +83 -0
  55. data/web/views/_job_info.erb +1 -1
  56. data/web/views/busy.erb +50 -19
  57. data/web/views/dashboard.erb +14 -6
  58. data/web/views/dead.erb +1 -1
  59. data/web/views/layout.erb +2 -1
  60. data/web/views/morgue.erb +6 -6
  61. data/web/views/queue.erb +1 -1
  62. data/web/views/queues.erb +10 -2
  63. data/web/views/retries.erb +7 -7
  64. data/web/views/retry.erb +1 -1
  65. data/web/views/scheduled.erb +1 -1
  66. metadata +26 -50
  67. data/.circleci/config.yml +0 -82
  68. data/.github/contributing.md +0 -32
  69. data/.github/issue_template.md +0 -11
  70. data/.gitignore +0 -13
  71. data/.standard.yml +0 -20
  72. data/3.0-Upgrade.md +0 -70
  73. data/4.0-Upgrade.md +0 -53
  74. data/5.0-Upgrade.md +0 -56
  75. data/6.0-Upgrade.md +0 -72
  76. data/COMM-LICENSE +0 -97
  77. data/Ent-2.0-Upgrade.md +0 -37
  78. data/Ent-Changes.md +0 -256
  79. data/Gemfile +0 -24
  80. data/Gemfile.lock +0 -196
  81. data/Pro-2.0-Upgrade.md +0 -138
  82. data/Pro-3.0-Upgrade.md +0 -44
  83. data/Pro-4.0-Upgrade.md +0 -35
  84. data/Pro-5.0-Upgrade.md +0 -25
  85. data/Pro-Changes.md +0 -776
  86. data/Rakefile +0 -10
  87. data/code_of_conduct.md +0 -50
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this file originally based on authenticity_token.rb from the sinatra/rack-protection project
4
+ #
5
+ # The MIT License (MIT)
6
+ #
7
+ # Copyright (c) 2011-2017 Konstantin Haase
8
+ # Copyright (c) 2015-2017 Zachary Scott
9
+ #
10
+ # Permission is hereby granted, free of charge, to any person obtaining
11
+ # a copy of this software and associated documentation files (the
12
+ # 'Software'), to deal in the Software without restriction, including
13
+ # without limitation the rights to use, copy, modify, merge, publish,
14
+ # distribute, sublicense, and/or sell copies of the Software, and to
15
+ # permit persons to whom the Software is furnished to do so, subject to
16
+ # the following conditions:
17
+ #
18
+ # The above copyright notice and this permission notice shall be
19
+ # included in all copies or substantial portions of the Software.
20
+ #
21
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
22
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+
29
+ require "securerandom"
30
+ require "base64"
31
+ require "rack/request"
32
+
33
+ module Sidekiq
34
+ class Web
35
+ class CsrfProtection
36
+ def initialize(app, options = nil)
37
+ @app = app
38
+ end
39
+
40
+ def call(env)
41
+ accept?(env) ? admit(env) : deny(env)
42
+ end
43
+
44
+ private
45
+
46
+ def admit(env)
47
+ # On each successful request, we create a fresh masked token
48
+ # which will be used in any forms rendered for this request.
49
+ s = session(env)
50
+ s[:csrf] ||= SecureRandom.base64(TOKEN_LENGTH)
51
+ env[:csrf_token] = mask_token(s[:csrf])
52
+ @app.call(env)
53
+ end
54
+
55
+ def safe?(env)
56
+ %w[GET HEAD OPTIONS TRACE].include? env["REQUEST_METHOD"]
57
+ end
58
+
59
+ def logger(env)
60
+ @logger ||= (env["rack.logger"] || ::Logger.new(env["rack.errors"]))
61
+ end
62
+
63
+ def deny(env)
64
+ logger(env).warn "attack prevented by #{self.class}"
65
+ [403, {"Content-Type" => "text/plain"}, ["Forbidden"]]
66
+ end
67
+
68
+ def session(env)
69
+ env["rack.session"] || fail(<<~EOM)
70
+ Sidekiq::Web needs a valid Rack session for CSRF protection. If this is a Rails app,
71
+ make sure you mount Sidekiq::Web *inside* your application routes:
72
+
73
+
74
+ Rails.application.routes.draw do
75
+ mount Sidekiq::Web => "/sidekiq"
76
+ ....
77
+ end
78
+
79
+
80
+ If this is a Rails app in API mode, you need to enable sessions.
81
+
82
+ https://guides.rubyonrails.org/api_app.html#using-session-middlewares
83
+
84
+ If this is a bare Rack app, use a session middleware before Sidekiq::Web:
85
+
86
+ # first, use IRB to create a shared secret key for sessions and commit it
87
+ require 'securerandom'; File.open(".session.key", "w") {|f| f.write(SecureRandom.hex(32)) }
88
+
89
+ # now use the secret with a session cookie middleware
90
+ use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400
91
+ run Sidekiq::Web
92
+
93
+ EOM
94
+ end
95
+
96
+ def accept?(env)
97
+ return true if safe?(env)
98
+
99
+ giventoken = ::Rack::Request.new(env).params["authenticity_token"]
100
+ valid_token?(env, giventoken)
101
+ end
102
+
103
+ TOKEN_LENGTH = 32
104
+
105
+ # Checks that the token given to us as a parameter matches
106
+ # the token stored in the session.
107
+ def valid_token?(env, giventoken)
108
+ return false if giventoken.nil? || giventoken.empty?
109
+
110
+ begin
111
+ token = decode_token(giventoken)
112
+ rescue ArgumentError # client input is invalid
113
+ return false
114
+ end
115
+
116
+ sess = session(env)
117
+ localtoken = sess[:csrf]
118
+
119
+ # Checks that Rack::Session::Cookie actualy contains the csrf toekn
120
+ return false if localtoken.nil?
121
+
122
+ # Rotate the session token after every use
123
+ sess[:csrf] = SecureRandom.base64(TOKEN_LENGTH)
124
+
125
+ # See if it's actually a masked token or not. We should be able
126
+ # to handle any unmasked tokens that we've issued without error.
127
+
128
+ if unmasked_token?(token)
129
+ compare_with_real_token token, localtoken
130
+ elsif masked_token?(token)
131
+ unmasked = unmask_token(token)
132
+ compare_with_real_token unmasked, localtoken
133
+ else
134
+ false # Token is malformed
135
+ end
136
+ end
137
+
138
+ # Creates a masked version of the authenticity token that varies
139
+ # on each request. The masking is used to mitigate SSL attacks
140
+ # like BREACH.
141
+ def mask_token(token)
142
+ token = decode_token(token)
143
+ one_time_pad = SecureRandom.random_bytes(token.length)
144
+ encrypted_token = xor_byte_strings(one_time_pad, token)
145
+ masked_token = one_time_pad + encrypted_token
146
+ Base64.strict_encode64(masked_token)
147
+ end
148
+
149
+ # Essentially the inverse of +mask_token+.
150
+ def unmask_token(masked_token)
151
+ # Split the token into the one-time pad and the encrypted
152
+ # value and decrypt it
153
+ token_length = masked_token.length / 2
154
+ one_time_pad = masked_token[0...token_length]
155
+ encrypted_token = masked_token[token_length..-1]
156
+ xor_byte_strings(one_time_pad, encrypted_token)
157
+ end
158
+
159
+ def unmasked_token?(token)
160
+ token.length == TOKEN_LENGTH
161
+ end
162
+
163
+ def masked_token?(token)
164
+ token.length == TOKEN_LENGTH * 2
165
+ end
166
+
167
+ def compare_with_real_token(token, local)
168
+ ::Rack::Utils.secure_compare(token.to_s, decode_token(local).to_s)
169
+ end
170
+
171
+ def decode_token(token)
172
+ Base64.strict_decode64(token)
173
+ end
174
+
175
+ def xor_byte_strings(s1, s2)
176
+ s1.bytes.zip(s2.bytes).map { |(c1, c2)| c1 ^ c2 }.pack("c*")
177
+ end
178
+ end
179
+ end
180
+ end
@@ -10,18 +10,25 @@ module Sidekiq
10
10
  module WebHelpers
11
11
  def strings(lang)
12
12
  @strings ||= {}
13
- @strings[lang] ||= begin
14
- # Allow sidekiq-web extensions to add locale paths
15
- # so extensions can be localized
16
- settings.locales.each_with_object({}) do |path, global|
17
- find_locale_files(lang).each do |file|
18
- strs = YAML.load(File.open(file))
19
- global.merge!(strs[lang])
20
- end
13
+
14
+ # Allow sidekiq-web extensions to add locale paths
15
+ # so extensions can be localized
16
+ @strings[lang] ||= settings.locales.each_with_object({}) do |path, global|
17
+ find_locale_files(lang).each do |file|
18
+ strs = YAML.load(File.open(file))
19
+ global.merge!(strs[lang])
21
20
  end
22
21
  end
23
22
  end
24
23
 
24
+ def singularize(str, count)
25
+ if count == 1 && str.respond_to?(:singularize) # rails
26
+ str.singularize
27
+ else
28
+ str
29
+ end
30
+ end
31
+
25
32
  def clear_caches
26
33
  @strings = nil
27
34
  @locale_files = nil
@@ -118,7 +125,7 @@ module Sidekiq
118
125
  # within is used by Sidekiq Pro
119
126
  def display_tags(job, within = nil)
120
127
  job.tags.map { |tag|
121
- "<span class='jobtag label label-info'>#{::Rack::Utils.escape_html(tag)}</span>"
128
+ "<span class='label label-info jobtag'>#{::Rack::Utils.escape_html(tag)}</span>"
122
129
  }.join(" ")
123
130
  end
124
131
 
@@ -156,16 +163,9 @@ module Sidekiq
156
163
  @stats ||= Sidekiq::Stats.new
157
164
  end
158
165
 
159
- def retries_with_score(score)
160
- Sidekiq.redis { |conn|
161
- conn.zrangebyscore("retry", score, score)
162
- }.map { |msg| Sidekiq.load_json(msg) }
163
- end
164
-
165
166
  def redis_connection
166
167
  Sidekiq.redis do |conn|
167
- c = conn.connection
168
- "redis://#{c[:location]}/#{c[:db]}"
168
+ conn.connection[:id]
169
169
  end
170
170
  end
171
171
 
@@ -207,12 +207,9 @@ module Sidekiq
207
207
 
208
208
  # Merge options with current params, filter safe params, and stringify to query string
209
209
  def qparams(options)
210
- # stringify
211
- options.keys.each do |key|
212
- options[key.to_s] = options.delete(key)
213
- end
210
+ stringified_options = options.transform_keys(&:to_s)
214
211
 
215
- to_query_string(params.merge(options))
212
+ to_query_string(params.merge(stringified_options))
216
213
  end
217
214
 
218
215
  def to_query_string(params)
@@ -239,7 +236,7 @@ module Sidekiq
239
236
  end
240
237
 
241
238
  def csrf_tag
242
- "<input type='hidden' name='authenticity_token' value='#{session[:csrf]}'/>"
239
+ "<input type='hidden' name='authenticity_token' value='#{env[:csrf_token]}'/>"
243
240
  end
244
241
 
245
242
  def to_display(arg)
@@ -267,7 +264,21 @@ module Sidekiq
267
264
  end
268
265
  end
269
266
 
267
+ def format_memory(rss_kb)
268
+ return "0" if rss_kb.nil? || rss_kb == 0
269
+
270
+ if rss_kb < 100_000
271
+ "#{number_with_delimiter(rss_kb)} KB"
272
+ elsif rss_kb < 10_000_000
273
+ "#{number_with_delimiter((rss_kb / 1024.0).to_i)} MB"
274
+ else
275
+ "#{number_with_delimiter((rss_kb / (1024.0 * 1024.0)).round(1))} GB"
276
+ end
277
+ end
278
+
270
279
  def number_with_delimiter(number)
280
+ return "" if number.nil?
281
+
271
282
  begin
272
283
  Float(number)
273
284
  rescue ArgumentError, TypeError
@@ -301,7 +312,7 @@ module Sidekiq
301
312
  end
302
313
 
303
314
  def environment_title_prefix
304
- environment = Sidekiq.options[:environment] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
315
+ environment = Sidekiq.options[:environment] || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
305
316
 
306
317
  "[#{environment.upcase}] " unless environment == "production"
307
318
  end
@@ -15,6 +15,10 @@ module Sidekiq
15
15
  REQUEST_METHOD = "REQUEST_METHOD"
16
16
  PATH_INFO = "PATH_INFO"
17
17
 
18
+ def head(path, &block)
19
+ route(HEAD, path, &block)
20
+ end
21
+
18
22
  def get(path, &block)
19
23
  route(GET, path, &block)
20
24
  end
@@ -39,7 +43,6 @@ module Sidekiq
39
43
  @routes ||= {GET => [], POST => [], PUT => [], PATCH => [], DELETE => [], HEAD => []}
40
44
 
41
45
  @routes[method] << WebRoute.new(method, path, block)
42
- @routes[HEAD] << WebRoute.new(method, path, block) if method == GET
43
46
  end
44
47
 
45
48
  def match(env)
@@ -66,7 +69,7 @@ module Sidekiq
66
69
  class WebRoute
67
70
  attr_accessor :request_method, :pattern, :block, :name
68
71
 
69
- NAMED_SEGMENTS_PATTERN = /\/([^\/]*):([^\.:$\/]+)/
72
+ NAMED_SEGMENTS_PATTERN = /\/([^\/]*):([^.:$\/]+)/
70
73
 
71
74
  def initialize(request_method, pattern, block)
72
75
  @request_method = request_method
@@ -94,9 +97,7 @@ module Sidekiq
94
97
  {} if path == matcher
95
98
  else
96
99
  path_match = path.match(matcher)
97
- if path_match
98
- Hash[path_match.names.map(&:to_sym).zip(path_match.captures)]
99
- end
100
+ path_match&.named_captures&.transform_keys(&:to_sym)
100
101
  end
101
102
  end
102
103
  end
data/lib/sidekiq/web.rb CHANGED
@@ -10,12 +10,11 @@ require "sidekiq/web/helpers"
10
10
  require "sidekiq/web/router"
11
11
  require "sidekiq/web/action"
12
12
  require "sidekiq/web/application"
13
+ require "sidekiq/web/csrf_protection"
13
14
 
14
- require "rack/protection"
15
-
15
+ require "rack/content_length"
16
16
  require "rack/builder"
17
- require "rack/file"
18
- require "rack/session/cookie"
17
+ require "rack/static"
19
18
 
20
19
  module Sidekiq
21
20
  class Web
@@ -31,7 +30,7 @@ module Sidekiq
31
30
  "Queues" => "queues",
32
31
  "Retries" => "retries",
33
32
  "Scheduled" => "scheduled",
34
- "Dead" => "morgue",
33
+ "Dead" => "morgue"
35
34
  }
36
35
 
37
36
  class << self
@@ -39,14 +38,6 @@ module Sidekiq
39
38
  self
40
39
  end
41
40
 
42
- def middlewares
43
- @middlewares ||= []
44
- end
45
-
46
- def use(*middleware_args, &block)
47
- middlewares << [middleware_args, block]
48
- end
49
-
50
41
  def default_tabs
51
42
  DEFAULT_TABS
52
43
  end
@@ -72,32 +63,45 @@ module Sidekiq
72
63
  opts.each { |key| set(key, false) }
73
64
  end
74
65
 
75
- # Helper for the Sinatra syntax: Sidekiq::Web.set(:session_secret, Rails.application.secrets...)
66
+ def middlewares
67
+ @middlewares ||= []
68
+ end
69
+
70
+ def use(*args, &block)
71
+ middlewares << [args, block]
72
+ end
73
+
76
74
  def set(attribute, value)
77
75
  send(:"#{attribute}=", value)
78
76
  end
79
77
 
80
- attr_accessor :app_url, :session_secret, :redis_pool, :sessions
78
+ def sessions=(val)
79
+ puts "WARNING: Sidekiq::Web.sessions= is no longer relevant and will be removed in Sidekiq 7.0. #{caller(1..1).first}"
80
+ end
81
+
82
+ def session_secret=(val)
83
+ puts "WARNING: Sidekiq::Web.session_secret= is no longer relevant and will be removed in Sidekiq 7.0. #{caller(1..1).first}"
84
+ end
85
+
86
+ attr_accessor :app_url, :redis_pool
81
87
  attr_writer :locales, :views
82
88
  end
83
89
 
84
90
  def self.inherited(child)
85
91
  child.app_url = app_url
86
- child.session_secret = session_secret
87
92
  child.redis_pool = redis_pool
88
- child.sessions = sessions
89
93
  end
90
94
 
91
95
  def settings
92
96
  self.class.settings
93
97
  end
94
98
 
95
- def use(*middleware_args, &block)
96
- middlewares << [middleware_args, block]
99
+ def middlewares
100
+ @middlewares ||= self.class.middlewares
97
101
  end
98
102
 
99
- def middlewares
100
- @middlewares ||= Web.middlewares.dup
103
+ def use(*args, &block)
104
+ middlewares << [args, block]
101
105
  end
102
106
 
103
107
  def call(env)
@@ -125,18 +129,8 @@ module Sidekiq
125
129
  send(:"#{attribute}=", value)
126
130
  end
127
131
 
128
- # Default values
129
- set :sessions, true
130
-
131
- attr_writer :sessions
132
-
133
- def sessions
134
- unless instance_variable_defined?("@sessions")
135
- @sessions = self.class.sessions
136
- @sessions = @sessions.to_hash.dup if @sessions.respond_to?(:to_hash)
137
- end
138
-
139
- @sessions
132
+ def sessions=(val)
133
+ puts "Sidekiq::Web#sessions= is no longer relevant and will be removed in Sidekiq 7.0. #{caller[2..2].first}"
140
134
  end
141
135
 
142
136
  def self.register(extension)
@@ -145,50 +139,20 @@ module Sidekiq
145
139
 
146
140
  private
147
141
 
148
- def using?(middleware)
149
- middlewares.any? do |(m, _)|
150
- m.is_a?(Array) && (m[0] == middleware || m[0].is_a?(middleware))
151
- end
152
- end
153
-
154
- def build_sessions
155
- middlewares = self.middlewares
156
-
157
- unless using?(::Rack::Protection) || ENV["RACK_ENV"] == "test"
158
- middlewares.unshift [[::Rack::Protection, {use: :authenticity_token}], nil]
159
- end
160
-
161
- s = sessions
162
- return unless s
163
-
164
- unless using? ::Rack::Session::Cookie
165
- unless (secret = Web.session_secret)
166
- require "securerandom"
167
- secret = SecureRandom.hex(64)
168
- end
169
-
170
- options = {secret: secret}
171
- options = options.merge(s.to_hash) if s.respond_to? :to_hash
172
-
173
- middlewares.unshift [[::Rack::Session::Cookie, options], nil]
174
- end
175
- end
176
-
177
142
  def build
178
- build_sessions
179
-
180
- middlewares = self.middlewares
181
143
  klass = self.class
144
+ m = middlewares
182
145
 
183
- ::Rack::Builder.new do
184
- %w[stylesheets javascripts images].each do |asset_dir|
185
- map "/#{asset_dir}" do
186
- run ::Rack::File.new("#{ASSETS}/#{asset_dir}", {"Cache-Control" => "public, max-age=86400"})
187
- end
188
- end
189
-
190
- middlewares.each { |middleware, block| use(*middleware, &block) }
146
+ rules = []
147
+ rules = [[:all, {"Cache-Control" => "public, max-age=86400"}]] unless ENV["SIDEKIQ_WEB_TESTING"]
191
148
 
149
+ ::Rack::Builder.new do
150
+ use Rack::Static, urls: ["/stylesheets", "/images", "/javascripts"],
151
+ root: ASSETS,
152
+ cascade: true,
153
+ header_rules: rules
154
+ m.each { |middleware, block| use(*middleware, &block) }
155
+ use Sidekiq::Web::CsrfProtection unless $TESTING
192
156
  run WebApplication.new(klass)
193
157
  end
194
158
  end
@@ -48,8 +48,8 @@ module Sidekiq
48
48
  # In practice, any option is allowed. This is the main mechanism to configure the
49
49
  # options for a specific job.
50
50
  def sidekiq_options(opts = {})
51
- opts = Hash[opts.map { |k, v| [k.to_s, v] }] # stringify
52
- self.sidekiq_options_hash = get_sidekiq_options.merge(Hash[opts.map { |k, v| [k.to_s, v] }])
51
+ opts = opts.transform_keys(&:to_s) # stringify
52
+ self.sidekiq_options_hash = get_sidekiq_options.merge(opts)
53
53
  end
54
54
 
55
55
  def sidekiq_retry_in(&block)
@@ -235,12 +235,9 @@ module Sidekiq
235
235
 
236
236
  def client_push(item) # :nodoc:
237
237
  pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options["pool"] || Sidekiq.redis_pool
238
- # stringify
239
- item.keys.each do |key|
240
- item[key.to_s] = item.delete(key)
241
- end
238
+ stringified_item = item.transform_keys(&:to_s)
242
239
 
243
- Sidekiq::Client.new(pool).push(item)
240
+ Sidekiq::Client.new(pool).push(stringified_item)
244
241
  end
245
242
  end
246
243
  end
data/lib/sidekiq.rb CHANGED
@@ -20,6 +20,7 @@ module Sidekiq
20
20
  labels: [],
21
21
  concurrency: 10,
22
22
  require: ".",
23
+ strict: true,
23
24
  environment: nil,
24
25
  timeout: 25,
25
26
  poll_interval_average: nil,
@@ -30,16 +31,16 @@ module Sidekiq
30
31
  startup: [],
31
32
  quiet: [],
32
33
  shutdown: [],
33
- heartbeat: [],
34
+ heartbeat: []
34
35
  },
35
36
  dead_max_jobs: 10_000,
36
37
  dead_timeout_in_seconds: 180 * 24 * 60 * 60, # 6 months
37
- reloader: proc { |&block| block.call },
38
+ reloader: proc { |&block| block.call }
38
39
  }
39
40
 
40
41
  DEFAULT_WORKER_OPTIONS = {
41
42
  "retry" => true,
42
- "queue" => "default",
43
+ "queue" => "default"
43
44
  }
44
45
 
45
46
  FAKE_INFO = {
@@ -47,7 +48,7 @@ module Sidekiq
47
48
  "uptime_in_days" => "9999",
48
49
  "connected_clients" => "9999",
49
50
  "used_memory_human" => "9P",
50
- "used_memory_peak_human" => "9P",
51
+ "used_memory_peak_human" => "9P"
51
52
  }
52
53
 
53
54
  def self.❨╯°□°❩╯︵┻━┻
@@ -95,10 +96,11 @@ module Sidekiq
95
96
  retryable = true
96
97
  begin
97
98
  yield conn
98
- rescue Redis::CommandError => ex
99
+ rescue Redis::BaseError => ex
99
100
  # 2550 Failover can cause the server to become a replica, need
100
101
  # to disconnect and reopen the socket to get back to the primary.
101
- if retryable && ex.message =~ /READONLY/
102
+ # 4495 Use the same logic if we have a "Not enough replicas" error from the primary
103
+ if retryable && ex.message =~ /READONLY|NOREPLICAS/
102
104
  conn.disconnect!
103
105
  retryable = false
104
106
  retry
@@ -154,7 +156,7 @@ module Sidekiq
154
156
 
155
157
  def self.default_worker_options=(hash)
156
158
  # stringify
157
- @default_worker_options = default_worker_options.merge(Hash[hash.map { |k, v| [k.to_s, v] }])
159
+ @default_worker_options = default_worker_options.merge(hash.transform_keys(&:to_s))
158
160
  end
159
161
 
160
162
  def self.default_worker_options
@@ -196,7 +198,7 @@ module Sidekiq
196
198
  end
197
199
 
198
200
  def self.logger
199
- @logger ||= Sidekiq::Logger.new(STDOUT, level: Logger::INFO)
201
+ @logger ||= Sidekiq::Logger.new($stdout, level: Logger::INFO)
200
202
  end
201
203
 
202
204
  def self.logger=(logger)
@@ -210,6 +212,10 @@ module Sidekiq
210
212
  @logger = logger
211
213
  end
212
214
 
215
+ def self.pro?
216
+ defined?(Sidekiq::Pro)
217
+ end
218
+
213
219
  # How frequently Redis should be checked by a random Sidekiq process for
214
220
  # scheduled and retriable jobs. Each individual process will take turns by
215
221
  # waiting some multiple of this value.
data/sidekiq.gemspec CHANGED
@@ -5,17 +5,24 @@ Gem::Specification.new do |gem|
5
5
  gem.email = ["mperham@gmail.com"]
6
6
  gem.summary = "Simple, efficient background processing for Ruby"
7
7
  gem.description = "Simple, efficient background processing for Ruby."
8
- gem.homepage = "http://sidekiq.org"
8
+ gem.homepage = "https://sidekiq.org"
9
9
  gem.license = "LGPL-3.0"
10
10
 
11
11
  gem.executables = ["sidekiq", "sidekiqmon"]
12
- gem.files = `git ls-files | grep -Ev '^(test|myapp|examples)'`.split("\n")
12
+ gem.files = ["sidekiq.gemspec", "README.md", "Changes.md", "LICENSE"] + `git ls-files | grep -E '^(bin|lib|web)'`.split("\n")
13
13
  gem.name = "sidekiq"
14
14
  gem.version = Sidekiq::VERSION
15
15
  gem.required_ruby_version = ">= 2.5.0"
16
16
 
17
- gem.add_dependency "redis", ">= 4.1.0"
17
+ gem.metadata = {
18
+ "homepage_uri" => "https://sidekiq.org",
19
+ "bug_tracker_uri" => "https://github.com/mperham/sidekiq/issues",
20
+ "documentation_uri" => "https://github.com/mperham/sidekiq/wiki",
21
+ "changelog_uri" => "https://github.com/mperham/sidekiq/blob/master/Changes.md",
22
+ "source_code_uri" => "https://github.com/mperham/sidekiq"
23
+ }
24
+
25
+ gem.add_dependency "redis", ">= 4.2.0"
18
26
  gem.add_dependency "connection_pool", ">= 2.2.2"
19
- gem.add_dependency "rack", ">= 2.0.0"
20
- gem.add_dependency "rack-protection", ">= 2.0.0"
27
+ gem.add_dependency "rack", "~> 2.0"
21
28
  end