sidekiq 8.1.7 → 8.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +12 -0
  3. data/README.md +3 -3
  4. data/lib/sidekiq/api.rb +12 -10
  5. data/lib/sidekiq/cli.rb +5 -2
  6. data/lib/sidekiq/config.rb +26 -1
  7. data/lib/sidekiq/embedded.rb +1 -1
  8. data/lib/sidekiq/job/iterable/active_record_enumerator.rb +1 -1
  9. data/lib/sidekiq/job/iterable.rb +1 -1
  10. data/lib/sidekiq/job.rb +55 -64
  11. data/lib/sidekiq/job_logger.rb +5 -0
  12. data/lib/sidekiq/job_util.rb +7 -2
  13. data/lib/sidekiq/metrics/shared.rb +1 -1
  14. data/lib/sidekiq/processor.rb +2 -0
  15. data/lib/sidekiq/redis_client_adapter.rb +5 -3
  16. data/lib/sidekiq/redis_connection.rb +18 -9
  17. data/lib/sidekiq/tui/tabs/base_tab.rb +19 -0
  18. data/lib/sidekiq/tui/tabs/busy.rb +1 -1
  19. data/lib/sidekiq/tui/tabs/home.rb +1 -1
  20. data/lib/sidekiq/tui.rb +6 -31
  21. data/lib/sidekiq/version.rb +1 -1
  22. data/lib/sidekiq/web/action.rb +2 -2
  23. data/lib/sidekiq/web/application.rb +5 -5
  24. data/lib/sidekiq/web/helpers.rb +24 -2
  25. data/lib/sidekiq/web.rb +2 -2
  26. data/sidekiq.gemspec +1 -1
  27. data/web/assets/javascripts/application.js +1 -0
  28. data/web/locales/da.yml +34 -0
  29. data/web/locales/de.yml +29 -1
  30. data/web/locales/es.yml +2 -0
  31. data/web/locales/fr.yml +11 -0
  32. data/web/locales/it.yml +2 -0
  33. data/web/locales/ja.yml +19 -0
  34. data/web/locales/ko.yml +42 -0
  35. data/web/locales/nb.yml +32 -0
  36. data/web/locales/nl.yml +41 -0
  37. data/web/locales/pl.yml +50 -0
  38. data/web/locales/pt-BR.yml +13 -0
  39. data/web/locales/pt.yml +42 -0
  40. data/web/locales/ru.yml +26 -0
  41. data/web/locales/sv.yml +41 -0
  42. data/web/locales/tr.yml +9 -0
  43. data/web/locales/uk.yml +9 -0
  44. data/web/locales/ur.yml +34 -4
  45. data/web/locales/zh-CN.yml +4 -0
  46. data/web/locales/zh-TW.yml +18 -0
  47. data/web/views/_job_info.html.erb +6 -6
  48. data/web/views/_nav.html.erb +3 -9
  49. data/web/views/busy.html.erb +5 -4
  50. data/web/views/dead.html.erb +1 -1
  51. data/web/views/layout.html.erb +1 -1
  52. data/web/views/morgue.html.erb +2 -1
  53. data/web/views/queues.html.erb +1 -0
  54. data/web/views/retries.html.erb +3 -2
  55. data/web/views/scheduled.html.erb +2 -1
  56. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e02b7ba4c390eb2a743bc62a8938cedd64ee940a6e128b2c517d9c3f27649543
4
- data.tar.gz: 86b1e8925322fb00b3d443c6aa8762d7d06f9a564276bf1b210c0415c8d571b4
3
+ metadata.gz: 9d57273306fa12b0b979c8bef039fd8457a7c09bdf2c66661e8e301be1300483
4
+ data.tar.gz: 45e32a880a7a5c2df9b885168775febdc8acc789c9ee321f2fff5f2295b0811d
5
5
  SHA512:
6
- metadata.gz: 63fd4147cf1a9ed566f47266a0c88eb966756285f4404714f2487783a1b754604ab00d5d9b4514002a116598f6005776c6db305c8d66192ec5c8e9b84af71595
7
- data.tar.gz: a904f9f6963083f76f5645990f068f31b5f3a1a13376d73744b693d6f2e0e2d551be420d70b9c6f97d3ae3ae6691140d21af6357e208e275228ba0061e92df14
6
+ metadata.gz: 2dde59200acb52993df285a82744a1da14e97cf70865333df817db73d8b76ae3c11dc83b36a9fe3a1cff7b0915fdb75721db060eb118300150d38341ea7057f1
7
+ data.tar.gz: de94f1d9b9be56f99ba8270ff121d70cf561c072ec0afdfc13b0ffd23f9c0fdb75295b8c6fe7243f6a1d425c18fa344c7737d9b7fef75e03c65cc48dee0f4019
data/Changes.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  [Sidekiq Changes](https://github.com/sidekiq/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/sidekiq/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/sidekiq/sidekiq/blob/main/Ent-Changes.md)
4
4
 
5
+ 8.1.8
6
+ ----------
7
+
8
+ - Define job class attributes once instead of a set of closures per job class, saving ~6KB of retained memory per job class
9
+ - Fix cancellation of iterable jobs before their first checkpoint [#7099]
10
+ - Do not count or log an interrupted iterable job as a failure [#7103]
11
+ - `config.redis=` now raises if the Redis connection pool was already created, instead of silently ignoring the new settings. The error names the code which created the pool. Apps which configure Sidekiq inside `Rails.application.reloader.to_prepare` should move that code out: `to_prepare` runs again on every code reload in development, and the second run will raise. `Sidekiq::CurrentAttributes.persist("Current")` takes a String, so it does not need `to_prepare` either [#7115]
12
+ - Refuse to start with a shutdown timeout (`-t`) below 3 seconds: a job pushed back at hard shutdown could be lost [#7129]
13
+ - Add missing strings for many non-English locales
14
+ - Misc bug fixes
15
+ - Migrate wiki to sidekiq.org/wiki
16
+
5
17
  8.1.7
6
18
  ----------
7
19
 
data/README.md CHANGED
@@ -32,7 +32,7 @@ Installation
32
32
  Getting Started
33
33
  -----------------
34
34
 
35
- See the [Getting Started wiki page](https://github.com/sidekiq/sidekiq/wiki/Getting-Started) and follow the simple setup process.
35
+ See the [Getting Started wiki page](https://sidekiq.org/wiki/Getting-Started) and follow the simple setup process.
36
36
  You can watch [this YouTube playlist](https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1) to learn all about
37
37
  Sidekiq and see its features in action. Here's the Web UI:
38
38
 
@@ -78,7 +78,7 @@ Problems?
78
78
  **Do not directly email any Sidekiq committers with questions or problems.**
79
79
  A community is best served when discussions are held in public.
80
80
 
81
- If you have a problem, please review the [FAQ](https://github.com/sidekiq/sidekiq/wiki/FAQ) and [Troubleshooting](https://github.com/sidekiq/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages.
81
+ If you have a problem, please review the [FAQ](https://sidekiq.org/wiki/FAQ) and [Troubleshooting](https://sidekiq.org/wiki/Problems-and-Troubleshooting) wiki pages.
82
82
  Searching the [issues](https://github.com/sidekiq/sidekiq/issues) for your problem is also a good idea.
83
83
 
84
84
  Sidekiq Pro and Sidekiq Enterprise customers get private email support.
@@ -86,7 +86,7 @@ You can purchase at https://sidekiq.org; email support@contribsys.com for help.
86
86
 
87
87
  Useful resources:
88
88
 
89
- * Product documentation is in the [wiki](https://github.com/sidekiq/sidekiq/wiki).
89
+ * Product documentation is in the [wiki](https://sidekiq.org/wiki).
90
90
  * Occasional announcements are made to the [@sidekiq](https://ruby.social/@sidekiq) Mastodon account.
91
91
  * The [Sidekiq tag](https://stackoverflow.com/questions/tagged/sidekiq) on Stack Overflow has lots of useful Q & A.
92
92
  * Join us in the `sidekiq` tag on the [Ruby Users Forum](https://www.rubyforum.org/tag/sidekiq).
data/lib/sidekiq/api.rb CHANGED
@@ -857,15 +857,17 @@ module Sidekiq
857
857
  }
858
858
 
859
859
  msg = matched.first
860
- if msg
861
- yield msg
862
- @_size -= 1
863
- end
864
-
865
- # push the rest back onto the sorted set
866
- conn.multi do |transaction|
867
- nonmatched.each do |message|
868
- transaction.zadd(name, score.to_f.to_s, message)
860
+ begin
861
+ if msg
862
+ yield msg
863
+ @_size -= 1
864
+ end
865
+ ensure
866
+ # push the rest back onto the sorted set
867
+ conn.multi do |transaction|
868
+ nonmatched.each do |message|
869
+ transaction.zadd(name, score.to_f.to_s, message)
870
+ end
869
871
  end
870
872
  end
871
873
  end
@@ -1358,7 +1360,7 @@ module Sidekiq
1358
1360
  @records = Sidekiq.redis do |c|
1359
1361
  # This throws away expired profiles
1360
1362
  c.zremrangebyscore("profiles", "-inf", Time.now.to_f.to_s)
1361
- # retreive records, newest to oldest
1363
+ # retrieve records, newest to oldest
1362
1364
  c.zrange("profiles", "+inf", 0, "byscore", "rev")
1363
1365
  end
1364
1366
  end
data/lib/sidekiq/cli.rb CHANGED
@@ -85,7 +85,7 @@ module Sidekiq # :nodoc:
85
85
 
86
86
  WARNING: Your Redis instance will evict Sidekiq data under heavy load.
87
87
  The 'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}').
88
- See: https://github.com/sidekiq/sidekiq/wiki/Using-Redis#memory
88
+ See: https://sidekiq.org/wiki/Using-Redis#memory
89
89
 
90
90
  EOM
91
91
  end
@@ -144,7 +144,7 @@ module Sidekiq # :nodoc:
144
144
 
145
145
  HOLIDAY_COLORS = {
146
146
  # got other color-specific holidays from around the world?
147
- # https://developer-book.com/post/definitive-guide-for-colored-text-in-terminal/#256-color-escape-codes
147
+ # https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
148
148
  "3-17" => "\e[1;32m", # St. Patrick's Day green
149
149
  "10-31" => "\e[38;5;208m" # Halloween orange
150
150
  }
@@ -336,6 +336,9 @@ module Sidekiq # :nodoc:
336
336
  [:concurrency, :timeout].each do |opt|
337
337
  raise ArgumentError, "#{opt}: #{@config[opt]} is not a valid value" if @config[opt].to_i <= 0
338
338
  end
339
+
340
+ # timeout needs to be larger than BasicFetch::TIMEOUT + Manager::PAUSE_TIME
341
+ raise ArgumentError, "-t value too short, must be >= 3" if @config[:timeout].to_i < 3
339
342
  end
340
343
 
341
344
  def parse_options(argv)
@@ -65,6 +65,8 @@ module Sidekiq
65
65
  @options[:error_handlers] << ERROR_HANDLER if @options[:error_handlers].empty?
66
66
  @directory = {}
67
67
  @redis_config = {}
68
+ @redis = nil
69
+ @redis_origin = nil
68
70
  @capsules = {}
69
71
  end
70
72
 
@@ -143,6 +145,18 @@ module Sidekiq
143
145
 
144
146
  # All capsules must use the same Redis configuration
145
147
  def redis=(hash)
148
+ if @redis
149
+ raise <<~MESSAGE
150
+ An attempt was made to configure Sidekiq Redis with `config.redis = ...` after the
151
+ connection pool was already created. This might come from another initializer,
152
+ or a background process started by a gem.
153
+
154
+ The pool was created from:
155
+ #{@redis_origin.join("\n ")}
156
+
157
+ MESSAGE
158
+ end
159
+
146
160
  @redis_config = @redis_config.merge(hash)
147
161
  end
148
162
 
@@ -157,7 +171,18 @@ module Sidekiq
157
171
  def local_redis_pool
158
172
  # this is our internal client/housekeeping pool. each capsule has its
159
173
  # own pool for executing threads.
160
- @redis ||= new_redis_pool(10, "internal")
174
+ return @redis if @redis
175
+
176
+ @redis_origin = pool_origin
177
+ @redis = new_redis_pool(10, "internal")
178
+ end
179
+
180
+ # Remember which code created the pool, so a future error message can possibly reference it
181
+ def pool_origin
182
+ lib_dir = File.expand_path("..", __dir__)
183
+ frames = caller_locations(1, 30)
184
+ app = frames.reject { |loc| loc.path.start_with?(lib_dir) }
185
+ (app.empty? ? frames : app).first(5)
161
186
  end
162
187
 
163
188
  def new_redis_pool(size, name = "unset")
@@ -52,7 +52,7 @@ module Sidekiq
52
52
 
53
53
  WARNING: Your Redis instance will evict Sidekiq data under heavy load.
54
54
  The 'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}').
55
- See: https://github.com/sidekiq/sidekiq/wiki/Using-Redis#memory
55
+ See: https://sidekiq.org/wiki/Using-Redis#memory
56
56
 
57
57
  EOM
58
58
  end
@@ -35,7 +35,7 @@ module Sidekiq
35
35
  options[:of] ||= options.delete(:batch_size)
36
36
 
37
37
  @relation.in_batches(**options, start: @cursor) do |relation|
38
- first_record = relation.first
38
+ first_record = (options[:order] == :desc) ? relation.last : relation.first
39
39
  yielder.yield(relation, first_record.id)
40
40
  end
41
41
  end
@@ -185,7 +185,7 @@ module Sidekiq
185
185
 
186
186
  unless state.empty?
187
187
  @_executions = state["ex"].to_i
188
- @_cursor = Sidekiq.load_json(state["c"])
188
+ @_cursor = Sidekiq.load_json(state["c"]) if state.key?("c")
189
189
  @_runtime = state["rt"].to_f
190
190
  end
191
191
  end
data/lib/sidekiq/job.rb CHANGED
@@ -46,16 +46,48 @@ module Sidekiq
46
46
  # The Options module is extracted so we can include it in ActiveJob::Base
47
47
  # and allow native AJs to configure Sidekiq features/internals.
48
48
  module Options
49
+ ATTRIBUTES = %i[sidekiq_options_hash sidekiq_retry_in_block sidekiq_retries_exhausted_block].freeze
50
+
49
51
  def self.included(base)
50
52
  base.extend(ClassMethods)
51
- base.sidekiq_class_attribute :sidekiq_options_hash
52
- base.sidekiq_class_attribute :sidekiq_retry_in_block
53
- base.sidekiq_class_attribute :sidekiq_retries_exhausted_block
53
+ # Including this module (again) starts the class over with default
54
+ # options, even when a superclass has set some.
55
+ ATTRIBUTES.each { |name| base.instance_variable_set(:"@#{name}", nil) }
54
56
  end
55
57
 
56
- module ClassMethods
57
- ACCESSOR_MUTEX = Mutex.new
58
+ # The readers fall back to the superclass, so a subclass sees its
59
+ # parent's value until it sets its own.
60
+ def self.define_class_attribute(mod, name)
61
+ mod.class_eval <<~RUBY, __FILE__, __LINE__ + 1
62
+ def #{name}
63
+ if instance_variable_defined?(:@#{name})
64
+ @#{name}
65
+ elsif (parent = superclass).respond_to?(:#{name})
66
+ parent.#{name}
67
+ end
68
+ end
69
+
70
+ def #{name}=(val)
71
+ @#{name} = val
72
+ end
73
+ RUBY
74
+ end
75
+
76
+ def self.define_instance_attribute(mod, name)
77
+ mod.class_eval <<~RUBY, __FILE__, __LINE__ + 1
78
+ def #{name}
79
+ if instance_variable_defined?(:@#{name})
80
+ @#{name}
81
+ else
82
+ self.class.#{name}
83
+ end
84
+ end
85
+
86
+ attr_writer :#{name}
87
+ RUBY
88
+ end
58
89
 
90
+ module ClassMethods
59
91
  ##
60
92
  # Allows customization for this type of Job.
61
93
  # Legal options:
@@ -89,72 +121,31 @@ module Sidekiq
89
121
  self.sidekiq_options_hash ||= Sidekiq.default_job_options
90
122
  end
91
123
 
124
+ # Defines class-level attributes that subclasses inherit and can
125
+ # override, with instance-level readers and writers.
126
+ #
127
+ # Values are stored in instance variables on the class that set them,
128
+ # and readers fall back to the superclass. This defines each method
129
+ # once, on the class that declares the attribute, rather than a new
130
+ # closure every time a subclass sets a value.
92
131
  def sidekiq_class_attribute(*attrs)
93
- instance_reader = true
94
- instance_writer = true
95
-
96
132
  attrs.each do |name|
97
- synchronized_getter = "__synchronized_#{name}"
98
-
99
- singleton_class.instance_eval do
100
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
101
- end
102
-
103
- define_singleton_method(synchronized_getter) { nil }
104
- singleton_class.class_eval do
105
- private(synchronized_getter)
106
- end
107
-
108
- define_singleton_method(name) { ACCESSOR_MUTEX.synchronize { send synchronized_getter } }
109
-
110
- ivar = "@#{name}"
111
-
112
- singleton_class.instance_eval do
113
- m = "#{name}="
114
- undef_method(m) if method_defined?(m) || private_method_defined?(m)
115
- end
116
- define_singleton_method(:"#{name}=") do |val|
117
- singleton_class.class_eval do
118
- ACCESSOR_MUTEX.synchronize do
119
- undef_method(synchronized_getter) if method_defined?(synchronized_getter) || private_method_defined?(synchronized_getter)
120
- define_method(synchronized_getter) { val }
121
- end
122
- end
123
-
124
- if singleton_class?
125
- class_eval do
126
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
127
- define_method(name) do
128
- if instance_variable_defined? ivar
129
- instance_variable_get ivar
130
- else
131
- singleton_class.send name
132
- end
133
- end
134
- end
135
- end
136
- val
137
- end
138
-
139
- if instance_reader
140
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
141
- define_method(name) do
142
- if instance_variable_defined?(ivar)
143
- instance_variable_get ivar
144
- else
145
- self.class.public_send name
146
- end
133
+ [singleton_class, self].each do |mod|
134
+ [name, :"#{name}="].each do |meth|
135
+ mod.undef_method(meth) if mod.method_defined?(meth) || mod.private_method_defined?(meth)
147
136
  end
148
137
  end
149
-
150
- if instance_writer
151
- m = "#{name}="
152
- undef_method(m) if method_defined?(m) || private_method_defined?(m)
153
- attr_writer name
154
- end
138
+ Options.define_class_attribute(singleton_class, name)
139
+ Options.define_instance_attribute(self, name)
140
+ instance_variable_set(:"@#{name}", nil)
155
141
  end
156
142
  end
157
143
  end
144
+
145
+ ATTRIBUTES.each do |name|
146
+ define_class_attribute(ClassMethods, name)
147
+ define_instance_attribute(self, name)
148
+ end
158
149
  end
159
150
 
160
151
  attr_accessor :jid
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "sidekiq/job_retry"
4
+
3
5
  module Sidekiq
4
6
  class JobLogger
5
7
  def initialize(config)
@@ -16,6 +18,9 @@ module Sidekiq
16
18
 
17
19
  Sidekiq::Context.add(:elapsed, elapsed(start))
18
20
  @logger.info { "done" } unless @skip
21
+ rescue JobRetry::Skip
22
+ Sidekiq::Context.add(:elapsed, elapsed(start))
23
+ raise
19
24
  rescue Exception
20
25
  Sidekiq::Context.add(:elapsed, elapsed(start))
21
26
  @logger.info { "fail" } unless @skip
@@ -27,7 +27,7 @@ module Sidekiq
27
27
  if (unsafe_item = json_unsafe?(args))
28
28
  msg = <<~EOM
29
29
  Job arguments to #{job_class} must be native JSON types, but #{unsafe_item.inspect} is a #{unsafe_item.class}.
30
- See https://github.com/sidekiq/sidekiq/wiki/Best-Practices
30
+ See https://sidekiq.org/wiki/Best-Practices
31
31
  To disable this error, add `Sidekiq.strict_args!(false)` to your initializer.
32
32
  EOM
33
33
 
@@ -79,7 +79,12 @@ module Sidekiq
79
79
 
80
80
  RECURSIVE_JSON_UNSAFE = {
81
81
  Integer => ->(val) {},
82
- Float => ->(val) {},
82
+ Float => ->(val) {
83
+ # JSON does not allow NaN / Infinity; reject them so strict_args!
84
+ # raises ArgumentError instead of a cryptic JSON::GeneratorError later.
85
+ return val unless val.finite?
86
+ nil
87
+ },
83
88
  TrueClass => ->(val) {},
84
89
  FalseClass => ->(val) {},
85
90
  NilClass => ->(val) {},
@@ -21,7 +21,7 @@ module Sidekiq
21
21
  # A precise time histogram stores every time. Instead we break times into a set of
22
22
  # known buckets and increment counts of the associated time bucket. Even if we call
23
23
  # the histogram a million times, we'll still only store 26 buckets.
24
- # NB: needs to be thread-safe or resiliant to races.
24
+ # NB: needs to be thread-safe or resilient to races.
25
25
  #
26
26
  # To store this data, we use Redis' BITFIELD command to store unsigned 16-bit counters
27
27
  # per bucket per klass per minute. It's unlikely that most people will be executing more
@@ -287,6 +287,8 @@ module Sidekiq
287
287
 
288
288
  begin
289
289
  yield
290
+ rescue JobRetry::Skip
291
+ raise
290
292
  rescue Exception
291
293
  FAILURE.incr
292
294
  raise
@@ -31,9 +31,11 @@ module Sidekiq
31
31
  zremrangebyrank zremrangebyscore]
32
32
 
33
33
  USED_COMMANDS.each do |name|
34
- define_method(name) do |*args, **kwargs|
35
- @client.call(name, *args, **kwargs)
36
- end
34
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
35
+ def #{name}(*args, **kwargs)
36
+ @client.call("#{name}", *args, **kwargs)
37
+ end
38
+ RUBY
37
39
  end
38
40
 
39
41
  private
@@ -33,7 +33,10 @@ module Sidekiq
33
33
  symbolized_options[:timeout] ||= 3
34
34
 
35
35
  redis_config = Sidekiq::RedisClientAdapter.new(symbolized_options)
36
- ConnectionPool.new(timeout: pool_timeout, size: size) do
36
+ # Only the main Ractor can fork, and connection_pool's fork registry
37
+ # is a non-shareable constant other Ractors can't touch.
38
+ main = Ractor.current == Ractor.main
39
+ ConnectionPool.new(timeout: pool_timeout, size: size, auto_reload_after_fork: main) do
37
40
  redis_config.new_client
38
41
  end
39
42
  end
@@ -70,18 +73,12 @@ module Sidekiq
70
73
  # unable to safely dump.
71
74
  keys = options.keys - [:logger, :ssl_params, :password, :sentinel_password]
72
75
  scrubbed_options = Marshal.load(Marshal.dump(options.slice(*keys)))
73
- if scrubbed_options[:url] && (uri = URI.parse(scrubbed_options[:url])) && uri.password
74
- uri.password = redacted
75
- scrubbed_options[:url] = uri.to_s
76
- end
76
+ scrubbed_options[:url] = redact_uri(scrubbed_options[:url], redacted) if scrubbed_options[:url]
77
77
  scrubbed_options[:password] = redacted if options.key?(:password)
78
78
  scrubbed_options[:sentinel_password] = redacted if options.key?(:sentinel_password)
79
79
  scrubbed_options[:sentinels]&.each do |sentinel|
80
80
  if sentinel.is_a?(String)
81
- if (uri = URI(sentinel)) && uri.password
82
- uri.password = redacted
83
- sentinel.replace(uri.to_s)
84
- end
81
+ sentinel.replace(redact_uri(sentinel, redacted))
85
82
  elsif sentinel[:password]
86
83
  sentinel[:password] = redacted
87
84
  end
@@ -89,6 +86,18 @@ module Sidekiq
89
86
  scrubbed_options
90
87
  end
91
88
 
89
+ # Replace the password in a Redis URL. A URL which can't be parsed may
90
+ # still hold a password, so it is redacted completely rather than letting
91
+ # URI::InvalidURIError (which quotes the URL) escape.
92
+ def redact_uri(url, redacted)
93
+ uri = URI.parse(url)
94
+ return url unless uri.password
95
+ uri.password = redacted
96
+ uri.to_s
97
+ rescue URI::InvalidURIError
98
+ redacted
99
+ end
100
+
92
101
  def determine_redis_provider
93
102
  # If you have this in your environment:
94
103
  # MY_REDIS_URL=redis://hostname.example.com:1238/4
@@ -16,6 +16,25 @@ module Sidekiq
16
16
  @parent.t(*)
17
17
  end
18
18
 
19
+ # Splits the described controls into rows which fit within +width+ columns.
20
+ def control_rows(width)
21
+ rows = []
22
+ row_width = 0
23
+ controls.each do |hash|
24
+ next unless hash[:description]
25
+
26
+ # rendered as "key: description "
27
+ control_width = (hash[:display] || hash[:code]).length + t(hash[:description]).length + 4
28
+ if rows.empty? || row_width + control_width > width
29
+ rows << []
30
+ row_width = 0
31
+ end
32
+ rows.last << hash
33
+ row_width += control_width
34
+ end
35
+ rows
36
+ end
37
+
19
38
  def reset_data
20
39
  @data = {selected: [], selected_row_index: 0}
21
40
  end
@@ -59,7 +59,7 @@ module Sidekiq
59
59
  constraints: [
60
60
  tui.constraint_length(4), # Stats
61
61
  tui.constraint_length(4), # Status
62
- tui.constraint_fill(1) # Graph
62
+ tui.constraint_fill(1) # Graph
63
63
  ]
64
64
  )
65
65
 
@@ -49,7 +49,7 @@ module Sidekiq
49
49
  direction: :vertical,
50
50
  constraints: [
51
51
  tui.constraint_length(4), # Stats
52
- tui.constraint_fill(1), # Graph
52
+ tui.constraint_fill(1), # Graph
53
53
  tui.constraint_length(4) # Redis
54
54
  ]
55
55
  )
data/lib/sidekiq/tui.rb CHANGED
@@ -60,12 +60,14 @@ module Sidekiq
60
60
  track_fps do
61
61
  if @showing == :main
62
62
  @tui.draw do |frame|
63
+ # Borders take 2 columns, and 2 rows along with the footer line.
64
+ control_rows = current_tab.control_rows(frame.area.width - 4)
63
65
  main_area, controls_area = @tui.layout_split(
64
66
  frame.area,
65
67
  direction: :vertical,
66
68
  constraints: [
67
69
  @tui.constraint_fill(1),
68
- @tui.constraint_length(5)
70
+ @tui.constraint_length([control_rows.size, 2].max + 3)
69
71
  ]
70
72
  )
71
73
 
@@ -91,7 +93,7 @@ module Sidekiq
91
93
  frame.render_widget(tabs, tabs_area)
92
94
 
93
95
  render_content_area(frame, content_area)
94
- render_controls(frame, controls_area)
96
+ render_controls(frame, controls_area, control_rows)
95
97
  end
96
98
  end
97
99
 
@@ -160,35 +162,8 @@ module Sidekiq
160
162
  current_tab.render(@tui, frame, content_area)
161
163
  end
162
164
 
163
- def render_controls(frame, area)
164
- active_keys = current_tab.controls.filter { |hash| hash[:description] }
165
-
166
- # Dynamically split controls based on terminal width
167
- # Estimate space needed: each control needs ~key_length + description_length + 4 chars for ": " and spacing
168
- available_width = area.width - 4 # Account for borders
169
-
170
- lines = []
171
- current_line = []
172
- current_width = 0
173
-
174
- active_keys.each do |hash|
175
- # Estimate control width: key + ": " + description + " " (spacing)
176
- key_text = hash[:display] || hash[:code]
177
- control_width = key_text.length + 2 + t(hash[:description]).length + 2
178
-
179
- if current_width + control_width > available_width && !current_line.empty?
180
- # Start a new line
181
- lines << controls_line(current_line)
182
- current_line = [hash]
183
- current_width = control_width
184
- else
185
- current_line << hash
186
- current_width += control_width
187
- end
188
- end
189
-
190
- # Add the last line
191
- lines << controls_line(current_line) unless current_line.empty?
165
+ def render_controls(frame, area, control_rows)
166
+ lines = control_rows.map { |keys| controls_line(keys) }
192
167
 
193
168
  # Ensure we have at least 2 lines for layout consistency
194
169
  while lines.length < 2
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sidekiq
4
- VERSION = "8.1.7"
4
+ VERSION = "8.1.8"
5
5
  MAJOR = 8
6
6
 
7
7
  def self.gem_version
@@ -118,7 +118,7 @@ module Sidekiq
118
118
  unless respond_to?(:"_erb_#{content}")
119
119
  views = options[:views] || Web.views
120
120
  filename = "#{views}/#{content}.html.erb"
121
- src = ERB.new(File.read(filename)).src
121
+ src = ERB.new(File.read(filename, encoding: "UTF-8")).src
122
122
 
123
123
  # Need to use lineno less by 1 because erb generates a
124
124
  # comment before the source code.
@@ -170,7 +170,7 @@ module Sidekiq
170
170
 
171
171
  class_eval <<-RUBY, ::Sidekiq::Web::LAYOUT, -1 # standard:disable Style/EvalWithLocation
172
172
  def _render
173
- #{ERB.new(File.read(::Sidekiq::Web::LAYOUT)).src}
173
+ #{ERB.new(File.read(::Sidekiq::Web::LAYOUT, encoding: "UTF-8")).src}
174
174
  end
175
175
  RUBY
176
176
  end
@@ -89,7 +89,7 @@ module Sidekiq
89
89
  end
90
90
 
91
91
  get "/busy" do
92
- @count = (url_params("count") || 100).to_i
92
+ @count = url_count(default_count: 100)
93
93
 
94
94
  # Use /busy?only=(jobs|processes) to limit page data
95
95
  only = url_params("only")
@@ -137,7 +137,7 @@ module Sidekiq
137
137
 
138
138
  halt(404) if !@name || @name !~ QUEUE_NAME
139
139
 
140
- @count = (url_params("count") || 25).to_i
140
+ @count = url_count
141
141
  @queue = Sidekiq::Queue.new(@name)
142
142
  (@current_page, @total_size, @jobs) = page("queue:#{@name}", url_params("page"), @count, reverse: url_params("direction") == "asc")
143
143
  @jobs = @jobs.map { |msg| Sidekiq::JobRecord.new(msg, @name) }
@@ -172,7 +172,7 @@ module Sidekiq
172
172
  if x && x != ""
173
173
  @dead = search(Sidekiq::DeadSet.new, x)
174
174
  else
175
- @count = (url_params("count") || 25).to_i
175
+ @count = url_count
176
176
  (@current_page, @total_size, @dead) = page("dead", url_params("page"), @count, reverse: true)
177
177
  @dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
178
178
  end
@@ -232,7 +232,7 @@ module Sidekiq
232
232
  if x && x != ""
233
233
  @retries = search(Sidekiq::RetrySet.new, x)
234
234
  else
235
- @count = (url_params("count") || 25).to_i
235
+ @count = url_count
236
236
  (@current_page, @total_size, @retries) = page("retry", url_params("page"), @count)
237
237
  @retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
238
238
  end
@@ -292,7 +292,7 @@ module Sidekiq
292
292
  if x && x != ""
293
293
  @scheduled = search(Sidekiq::ScheduledSet.new, x)
294
294
  else
295
- @count = (url_params("count") || 25).to_i
295
+ @count = url_count
296
296
  (@current_page, @total_size, @scheduled) = page("schedule", url_params("page"), @count)
297
297
  @scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
298
298
  end