sidekiq 7.1.4 → 7.3.9
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.
- checksums.yaml +4 -4
- data/Changes.md +204 -0
- data/README.md +5 -5
- data/bin/multi_queue_bench +271 -0
- data/bin/sidekiqload +21 -12
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +75 -0
- data/lib/generators/sidekiq/job_generator.rb +2 -0
- data/lib/sidekiq/api.rb +139 -44
- data/lib/sidekiq/capsule.rb +8 -3
- data/lib/sidekiq/cli.rb +4 -1
- data/lib/sidekiq/client.rb +26 -4
- data/lib/sidekiq/component.rb +22 -0
- data/lib/sidekiq/config.rb +40 -7
- data/lib/sidekiq/deploy.rb +4 -2
- data/lib/sidekiq/embedded.rb +2 -0
- data/lib/sidekiq/fetch.rb +1 -1
- data/lib/sidekiq/iterable_job.rb +55 -0
- data/lib/sidekiq/job/interrupt_handler.rb +24 -0
- data/lib/sidekiq/job/iterable/active_record_enumerator.rb +53 -0
- data/lib/sidekiq/job/iterable/csv_enumerator.rb +47 -0
- data/lib/sidekiq/job/iterable/enumerators.rb +135 -0
- data/lib/sidekiq/job/iterable.rb +294 -0
- data/lib/sidekiq/job.rb +14 -3
- data/lib/sidekiq/job_logger.rb +7 -6
- data/lib/sidekiq/job_retry.rb +9 -4
- data/lib/sidekiq/job_util.rb +2 -0
- data/lib/sidekiq/launcher.rb +7 -5
- data/lib/sidekiq/logger.rb +1 -1
- data/lib/sidekiq/metrics/query.rb +6 -1
- data/lib/sidekiq/metrics/shared.rb +15 -4
- data/lib/sidekiq/metrics/tracking.rb +20 -8
- data/lib/sidekiq/middleware/current_attributes.rb +46 -13
- data/lib/sidekiq/middleware/modules.rb +2 -0
- data/lib/sidekiq/monitor.rb +2 -1
- data/lib/sidekiq/paginator.rb +8 -2
- data/lib/sidekiq/processor.rb +21 -11
- data/lib/sidekiq/rails.rb +24 -13
- data/lib/sidekiq/redis_client_adapter.rb +25 -7
- data/lib/sidekiq/redis_connection.rb +37 -8
- data/lib/sidekiq/ring_buffer.rb +2 -0
- data/lib/sidekiq/scheduled.rb +2 -2
- data/lib/sidekiq/systemd.rb +2 -0
- data/lib/sidekiq/testing.rb +32 -13
- data/lib/sidekiq/transaction_aware_client.rb +7 -0
- data/lib/sidekiq/version.rb +5 -1
- data/lib/sidekiq/web/action.rb +26 -4
- data/lib/sidekiq/web/application.rb +58 -19
- data/lib/sidekiq/web/csrf_protection.rb +8 -5
- data/lib/sidekiq/web/helpers.rb +95 -35
- data/lib/sidekiq/web/router.rb +5 -2
- data/lib/sidekiq/web.rb +54 -2
- data/lib/sidekiq.rb +5 -3
- data/sidekiq.gemspec +3 -2
- data/web/assets/javascripts/application.js +26 -0
- data/web/assets/javascripts/dashboard-charts.js +37 -11
- data/web/assets/javascripts/dashboard.js +14 -10
- data/web/assets/javascripts/metrics.js +34 -0
- data/web/assets/stylesheets/application-rtl.css +10 -0
- data/web/assets/stylesheets/application.css +38 -3
- data/web/locales/en.yml +5 -1
- data/web/locales/fr.yml +0 -1
- data/web/locales/gd.yml +0 -1
- data/web/locales/it.yml +32 -1
- data/web/locales/ja.yml +0 -1
- data/web/locales/pt-br.yml +1 -2
- data/web/locales/tr.yml +100 -0
- data/web/locales/uk.yml +24 -1
- data/web/locales/zh-cn.yml +0 -1
- data/web/locales/zh-tw.yml +0 -1
- data/web/views/_footer.erb +12 -1
- data/web/views/_metrics_period_select.erb +1 -1
- data/web/views/_summary.erb +7 -7
- data/web/views/busy.erb +7 -7
- data/web/views/dashboard.erb +29 -36
- data/web/views/filtering.erb +6 -0
- data/web/views/layout.erb +6 -6
- data/web/views/metrics.erb +38 -30
- data/web/views/metrics_for_job.erb +29 -38
- data/web/views/morgue.erb +2 -2
- data/web/views/queue.erb +1 -1
- data/web/views/queues.erb +6 -2
- metadata +34 -13
data/lib/sidekiq/version.rb
CHANGED
data/lib/sidekiq/web/action.rb
CHANGED
@@ -22,6 +22,12 @@ module Sidekiq
|
|
22
22
|
throw :halt, [302, {Web::LOCATION => "#{request.base_url}#{location}"}, []]
|
23
23
|
end
|
24
24
|
|
25
|
+
def reload_page
|
26
|
+
current_location = request.referer.gsub(request.base_url, "")
|
27
|
+
redirect current_location
|
28
|
+
end
|
29
|
+
|
30
|
+
# deprecated, will warn in 8.0
|
25
31
|
def params
|
26
32
|
indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
|
27
33
|
|
@@ -31,8 +37,19 @@ module Sidekiq
|
|
31
37
|
indifferent_hash
|
32
38
|
end
|
33
39
|
|
34
|
-
|
35
|
-
|
40
|
+
# Use like `url_params("page")` within your action blocks
|
41
|
+
def url_params(key)
|
42
|
+
request.params[key]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Use like `route_params(:name)` within your action blocks
|
46
|
+
# key is required in 8.0, nil is only used for backwards compatibility
|
47
|
+
def route_params(key = nil)
|
48
|
+
if key
|
49
|
+
env[WebRouter::ROUTE_PARAMS][key]
|
50
|
+
else
|
51
|
+
env[WebRouter::ROUTE_PARAMS]
|
52
|
+
end
|
36
53
|
end
|
37
54
|
|
38
55
|
def session
|
@@ -42,8 +59,13 @@ module Sidekiq
|
|
42
59
|
def erb(content, options = {})
|
43
60
|
if content.is_a? Symbol
|
44
61
|
unless respond_to?(:"_erb_#{content}")
|
45
|
-
|
46
|
-
|
62
|
+
views = options[:views] || Web.settings.views
|
63
|
+
filename = "#{views}/#{content}.erb"
|
64
|
+
src = ERB.new(File.read(filename)).src
|
65
|
+
|
66
|
+
# Need to use lineno less by 1 because erb generates a
|
67
|
+
# comment before the source code.
|
68
|
+
WebAction.class_eval <<-RUBY, filename, -1 # standard:disable Style/EvalWithLocation
|
47
69
|
def _erb_#{content}
|
48
70
|
#{src}
|
49
71
|
end
|
@@ -5,7 +5,7 @@ module Sidekiq
|
|
5
5
|
extend WebRouter
|
6
6
|
|
7
7
|
REDIS_KEYS = %w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human]
|
8
|
-
|
8
|
+
CSP_HEADER_TEMPLATE = [
|
9
9
|
"default-src 'self' https: http:",
|
10
10
|
"child-src 'self'",
|
11
11
|
"connect-src 'self' https: http: wss: ws:",
|
@@ -15,8 +15,8 @@ module Sidekiq
|
|
15
15
|
"manifest-src 'self'",
|
16
16
|
"media-src 'self'",
|
17
17
|
"object-src 'none'",
|
18
|
-
"script-src 'self'
|
19
|
-
"style-src 'self' https: http: 'unsafe-inline'",
|
18
|
+
"script-src 'self' 'nonce-!placeholder!'",
|
19
|
+
"style-src 'self' https: http: 'unsafe-inline'", # TODO Nonce in 8.0
|
20
20
|
"worker-src 'self'",
|
21
21
|
"base-uri 'self'"
|
22
22
|
].join("; ").freeze
|
@@ -49,9 +49,9 @@ module Sidekiq
|
|
49
49
|
|
50
50
|
head "/" do
|
51
51
|
# HEAD / is the cheapest heartbeat possible,
|
52
|
-
# it hits Redis to ensure connectivity
|
53
|
-
|
54
|
-
""
|
52
|
+
# it hits Redis to ensure connectivity and returns
|
53
|
+
# the size of the default queue
|
54
|
+
Sidekiq.redis { |c| c.llen("queue:default") }.to_s
|
55
55
|
end
|
56
56
|
|
57
57
|
get "/" do
|
@@ -67,11 +67,15 @@ module Sidekiq
|
|
67
67
|
end
|
68
68
|
|
69
69
|
get "/metrics" do
|
70
|
+
x = params[:substr]
|
71
|
+
class_filter = (x.nil? || x == "") ? nil : Regexp.new(Regexp.escape(x), Regexp::IGNORECASE)
|
72
|
+
|
70
73
|
q = Sidekiq::Metrics::Query.new
|
71
74
|
@period = h((params[:period] || "")[0..1])
|
72
75
|
@periods = METRICS_PERIODS
|
73
76
|
minutes = @periods.fetch(@period, @periods.values.first)
|
74
|
-
@query_result = q.top_jobs(minutes: minutes)
|
77
|
+
@query_result = q.top_jobs(minutes: minutes, class_filter: class_filter)
|
78
|
+
|
75
79
|
erb(:metrics)
|
76
80
|
end
|
77
81
|
|
@@ -153,9 +157,15 @@ module Sidekiq
|
|
153
157
|
end
|
154
158
|
|
155
159
|
get "/morgue" do
|
156
|
-
|
157
|
-
|
158
|
-
|
160
|
+
x = params[:substr]
|
161
|
+
|
162
|
+
if x && x != ""
|
163
|
+
@dead = search(Sidekiq::DeadSet.new, x)
|
164
|
+
else
|
165
|
+
@count = (params["count"] || 25).to_i
|
166
|
+
(@current_page, @total_size, @dead) = page("dead", params["page"], @count, reverse: true)
|
167
|
+
@dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
168
|
+
end
|
159
169
|
|
160
170
|
erb(:morgue)
|
161
171
|
end
|
@@ -174,7 +184,7 @@ module Sidekiq
|
|
174
184
|
end
|
175
185
|
|
176
186
|
post "/morgue" do
|
177
|
-
redirect(request.path) unless
|
187
|
+
redirect(request.path) unless url_params("key")
|
178
188
|
|
179
189
|
params["key"].each do |key|
|
180
190
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
@@ -197,7 +207,7 @@ module Sidekiq
|
|
197
207
|
end
|
198
208
|
|
199
209
|
post "/morgue/:key" do
|
200
|
-
key = route_params
|
210
|
+
key = route_params(:key)
|
201
211
|
halt(404) unless key
|
202
212
|
|
203
213
|
job = Sidekiq::DeadSet.new.fetch(*parse_params(key)).first
|
@@ -207,9 +217,15 @@ module Sidekiq
|
|
207
217
|
end
|
208
218
|
|
209
219
|
get "/retries" do
|
210
|
-
|
211
|
-
|
212
|
-
|
220
|
+
x = url_params("substr")
|
221
|
+
|
222
|
+
if x && x != ""
|
223
|
+
@retries = search(Sidekiq::RetrySet.new, x)
|
224
|
+
else
|
225
|
+
@count = (params["count"] || 25).to_i
|
226
|
+
(@current_page, @total_size, @retries) = page("retry", params["page"], @count)
|
227
|
+
@retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
228
|
+
end
|
213
229
|
|
214
230
|
erb(:retries)
|
215
231
|
end
|
@@ -262,9 +278,15 @@ module Sidekiq
|
|
262
278
|
end
|
263
279
|
|
264
280
|
get "/scheduled" do
|
265
|
-
|
266
|
-
|
267
|
-
|
281
|
+
x = params[:substr]
|
282
|
+
|
283
|
+
if x && x != ""
|
284
|
+
@scheduled = search(Sidekiq::ScheduledSet.new, x)
|
285
|
+
else
|
286
|
+
@count = (params["count"] || 25).to_i
|
287
|
+
(@current_page, @total_size, @scheduled) = page("schedule", params["page"], @count)
|
288
|
+
@scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) }
|
289
|
+
end
|
268
290
|
|
269
291
|
erb(:scheduled)
|
270
292
|
end
|
@@ -328,6 +350,18 @@ module Sidekiq
|
|
328
350
|
json Sidekiq::Stats.new.queues
|
329
351
|
end
|
330
352
|
|
353
|
+
post "/change_locale" do
|
354
|
+
locale = params["locale"]
|
355
|
+
|
356
|
+
match = available_locales.find { |available|
|
357
|
+
locale == available
|
358
|
+
}
|
359
|
+
|
360
|
+
session[:locale] = match if match
|
361
|
+
|
362
|
+
reload_page
|
363
|
+
end
|
364
|
+
|
331
365
|
def call(env)
|
332
366
|
action = self.class.match(env)
|
333
367
|
return [404, {Rack::CONTENT_TYPE => "text/plain", Web::X_CASCADE => "pass"}, ["Not Found"]] unless action
|
@@ -350,13 +384,18 @@ module Sidekiq
|
|
350
384
|
Rack::CONTENT_TYPE => "text/html",
|
351
385
|
Rack::CACHE_CONTROL => "private, no-store",
|
352
386
|
Web::CONTENT_LANGUAGE => action.locale,
|
353
|
-
Web::CONTENT_SECURITY_POLICY =>
|
387
|
+
Web::CONTENT_SECURITY_POLICY => process_csp(env, CSP_HEADER_TEMPLATE),
|
388
|
+
Web::X_CONTENT_TYPE_OPTIONS => "nosniff"
|
354
389
|
}
|
355
390
|
# we'll let Rack calculate Content-Length for us.
|
356
391
|
[200, headers, [resp]]
|
357
392
|
end
|
358
393
|
end
|
359
394
|
|
395
|
+
def process_csp(env, input)
|
396
|
+
input.gsub("!placeholder!", env[:csp_nonce])
|
397
|
+
end
|
398
|
+
|
360
399
|
def self.helpers(mod = nil, &block)
|
361
400
|
if block
|
362
401
|
WebAction.class_eval(&block)
|
@@ -27,7 +27,6 @@
|
|
27
27
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
28
|
|
29
29
|
require "securerandom"
|
30
|
-
require "base64"
|
31
30
|
require "rack/request"
|
32
31
|
|
33
32
|
module Sidekiq
|
@@ -57,7 +56,7 @@ module Sidekiq
|
|
57
56
|
end
|
58
57
|
|
59
58
|
def logger(env)
|
60
|
-
@logger ||=
|
59
|
+
@logger ||= env["rack.logger"] || ::Logger.new(env["rack.errors"])
|
61
60
|
end
|
62
61
|
|
63
62
|
def deny(env)
|
@@ -116,7 +115,7 @@ module Sidekiq
|
|
116
115
|
sess = session(env)
|
117
116
|
localtoken = sess[:csrf]
|
118
117
|
|
119
|
-
# Checks that Rack::Session::Cookie
|
118
|
+
# Checks that Rack::Session::Cookie actually contains the csrf token
|
120
119
|
return false if localtoken.nil?
|
121
120
|
|
122
121
|
# Rotate the session token after every use
|
@@ -143,7 +142,7 @@ module Sidekiq
|
|
143
142
|
one_time_pad = SecureRandom.random_bytes(token.length)
|
144
143
|
encrypted_token = xor_byte_strings(one_time_pad, token)
|
145
144
|
masked_token = one_time_pad + encrypted_token
|
146
|
-
|
145
|
+
encode_token(masked_token)
|
147
146
|
end
|
148
147
|
|
149
148
|
# Essentially the inverse of +mask_token+.
|
@@ -168,8 +167,12 @@ module Sidekiq
|
|
168
167
|
::Rack::Utils.secure_compare(token.to_s, decode_token(local).to_s)
|
169
168
|
end
|
170
169
|
|
170
|
+
def encode_token(token)
|
171
|
+
[token].pack("m0").tr("+/", "-_")
|
172
|
+
end
|
173
|
+
|
171
174
|
def decode_token(token)
|
172
|
-
|
175
|
+
token.tr("-_", "+/").unpack1("m0")
|
173
176
|
end
|
174
177
|
|
175
178
|
def xor_byte_strings(s1, s2)
|
data/lib/sidekiq/web/helpers.rb
CHANGED
@@ -6,14 +6,57 @@ require "yaml"
|
|
6
6
|
require "cgi"
|
7
7
|
|
8
8
|
module Sidekiq
|
9
|
-
#
|
9
|
+
# These methods are available to pages within the Web UI and UI extensions.
|
10
|
+
# They are not public APIs for applications to use.
|
10
11
|
module WebHelpers
|
12
|
+
def style_tag(location, **kwargs)
|
13
|
+
global = location.match?(/:\/\//)
|
14
|
+
location = root_path + location if !global && !location.start_with?(root_path)
|
15
|
+
attrs = {
|
16
|
+
type: "text/css",
|
17
|
+
media: "screen",
|
18
|
+
rel: "stylesheet",
|
19
|
+
nonce: csp_nonce,
|
20
|
+
href: location
|
21
|
+
}
|
22
|
+
html_tag(:link, attrs.merge(kwargs))
|
23
|
+
end
|
24
|
+
|
25
|
+
def script_tag(location, **kwargs)
|
26
|
+
global = location.match?(/:\/\//)
|
27
|
+
location = root_path + location if !global && !location.start_with?(root_path)
|
28
|
+
attrs = {
|
29
|
+
type: "text/javascript",
|
30
|
+
nonce: csp_nonce,
|
31
|
+
src: location
|
32
|
+
}
|
33
|
+
html_tag(:script, attrs.merge(kwargs)) {}
|
34
|
+
end
|
35
|
+
|
36
|
+
# NB: keys and values are not escaped; do not allow user input
|
37
|
+
# in the attributes
|
38
|
+
private def html_tag(tagname, attrs)
|
39
|
+
s = +"<#{tagname}"
|
40
|
+
attrs.each_pair do |k, v|
|
41
|
+
next unless v
|
42
|
+
s << " #{k}=\"#{v}\""
|
43
|
+
end
|
44
|
+
if block_given?
|
45
|
+
s << ">"
|
46
|
+
yield s
|
47
|
+
s << "</#{tagname}>"
|
48
|
+
else
|
49
|
+
s << " />"
|
50
|
+
end
|
51
|
+
s
|
52
|
+
end
|
53
|
+
|
11
54
|
def strings(lang)
|
12
|
-
|
55
|
+
@@strings ||= {}
|
13
56
|
|
14
57
|
# Allow sidekiq-web extensions to add locale paths
|
15
58
|
# so extensions can be localized
|
16
|
-
|
59
|
+
@@strings[lang] ||= settings.locales.each_with_object({}) do |path, global|
|
17
60
|
find_locale_files(lang).each do |file|
|
18
61
|
strs = YAML.safe_load(File.read(file))
|
19
62
|
global.merge!(strs[lang])
|
@@ -21,6 +64,10 @@ module Sidekiq
|
|
21
64
|
end
|
22
65
|
end
|
23
66
|
|
67
|
+
def to_json(x)
|
68
|
+
Sidekiq.dump_json(x)
|
69
|
+
end
|
70
|
+
|
24
71
|
def singularize(str, count)
|
25
72
|
if count == 1 && str.respond_to?(:singularize) # rails
|
26
73
|
str.singularize
|
@@ -30,27 +77,48 @@ module Sidekiq
|
|
30
77
|
end
|
31
78
|
|
32
79
|
def clear_caches
|
33
|
-
|
34
|
-
|
35
|
-
|
80
|
+
@@strings = nil
|
81
|
+
@@locale_files = nil
|
82
|
+
@@available_locales = nil
|
36
83
|
end
|
37
84
|
|
38
85
|
def locale_files
|
39
|
-
|
86
|
+
@@locale_files ||= settings.locales.flat_map { |path|
|
40
87
|
Dir["#{path}/*.yml"]
|
41
88
|
}
|
42
89
|
end
|
43
90
|
|
44
91
|
def available_locales
|
45
|
-
|
92
|
+
@@available_locales ||= Set.new(locale_files.map { |path| File.basename(path, ".yml") })
|
46
93
|
end
|
47
94
|
|
48
95
|
def find_locale_files(lang)
|
49
96
|
locale_files.select { |file| file =~ /\/#{lang}\.yml$/ }
|
50
97
|
end
|
51
98
|
|
52
|
-
|
53
|
-
|
99
|
+
def search(jobset, substr)
|
100
|
+
resultset = jobset.scan(substr).to_a
|
101
|
+
@current_page = 1
|
102
|
+
@count = @total_size = resultset.size
|
103
|
+
resultset
|
104
|
+
end
|
105
|
+
|
106
|
+
def filtering(which)
|
107
|
+
erb(:filtering, locals: {which: which})
|
108
|
+
end
|
109
|
+
|
110
|
+
def filter_link(jid, within = "retries")
|
111
|
+
if within.nil?
|
112
|
+
::Rack::Utils.escape_html(jid)
|
113
|
+
else
|
114
|
+
"<a href='#{root_path}#{within}?substr=#{jid}'>#{::Rack::Utils.escape_html(jid)}</a>"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def display_tags(job, within = "retries")
|
119
|
+
job.tags.map { |tag|
|
120
|
+
"<span class='label label-info jobtag'>#{filter_link(tag, within)}</span>"
|
121
|
+
}.join(" ")
|
54
122
|
end
|
55
123
|
|
56
124
|
# This view helper provide ability display you html code in
|
@@ -96,7 +164,10 @@ module Sidekiq
|
|
96
164
|
#
|
97
165
|
# Inspiration taken from https://github.com/iain/http_accept_language/blob/master/lib/http_accept_language/parser.rb
|
98
166
|
def locale
|
99
|
-
|
167
|
+
# session[:locale] is set via the locale selector from the footer
|
168
|
+
@locale ||= if (l = session&.fetch(:locale, nil)) && available_locales.include?(l)
|
169
|
+
l
|
170
|
+
else
|
100
171
|
matched_locale = user_preferred_languages.map { |preferred|
|
101
172
|
preferred_language = preferred.split("-", 2).first
|
102
173
|
|
@@ -111,16 +182,10 @@ module Sidekiq
|
|
111
182
|
end
|
112
183
|
end
|
113
184
|
|
114
|
-
# within is used by Sidekiq Pro
|
115
|
-
def display_tags(job, within = nil)
|
116
|
-
job.tags.map { |tag|
|
117
|
-
"<span class='label label-info jobtag'>#{::Rack::Utils.escape_html(tag)}</span>"
|
118
|
-
}.join(" ")
|
119
|
-
end
|
120
|
-
|
121
185
|
# sidekiq/sidekiq#3243
|
122
186
|
def unfiltered?
|
123
|
-
|
187
|
+
s = url_params("substr")
|
188
|
+
yield unless s && s.size > 0
|
124
189
|
end
|
125
190
|
|
126
191
|
def get_locale
|
@@ -245,6 +310,10 @@ module Sidekiq
|
|
245
310
|
"<input type='hidden' name='authenticity_token' value='#{env[:csrf_token]}'/>"
|
246
311
|
end
|
247
312
|
|
313
|
+
def csp_nonce
|
314
|
+
env[:csp_nonce]
|
315
|
+
end
|
316
|
+
|
248
317
|
def to_display(arg)
|
249
318
|
arg.inspect
|
250
319
|
rescue
|
@@ -278,27 +347,17 @@ module Sidekiq
|
|
278
347
|
elsif rss_kb < 10_000_000
|
279
348
|
"#{number_with_delimiter((rss_kb / 1024.0).to_i)} MB"
|
280
349
|
else
|
281
|
-
"#{number_with_delimiter((rss_kb / (1024.0 * 1024.0))
|
350
|
+
"#{number_with_delimiter((rss_kb / (1024.0 * 1024.0)), precision: 1)} GB"
|
282
351
|
end
|
283
352
|
end
|
284
353
|
|
285
|
-
def number_with_delimiter(number)
|
286
|
-
|
287
|
-
|
288
|
-
begin
|
289
|
-
Float(number)
|
290
|
-
rescue ArgumentError, TypeError
|
291
|
-
return number
|
292
|
-
end
|
293
|
-
|
294
|
-
options = {delimiter: ",", separator: "."}
|
295
|
-
parts = number.to_s.to_str.split(".")
|
296
|
-
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
|
297
|
-
parts.join(options[:separator])
|
354
|
+
def number_with_delimiter(number, options = {})
|
355
|
+
precision = options[:precision] || 0
|
356
|
+
%(<span data-nwp="#{precision}">#{number.round(precision)}</span>)
|
298
357
|
end
|
299
358
|
|
300
359
|
def h(text)
|
301
|
-
::Rack::Utils.escape_html(text)
|
360
|
+
::Rack::Utils.escape_html(text.to_s)
|
302
361
|
rescue ArgumentError => e
|
303
362
|
raise unless e.message.eql?("invalid byte sequence in UTF-8")
|
304
363
|
text.encode!("UTF-16", "UTF-8", invalid: :replace, replace: "").encode!("UTF-8", "UTF-16")
|
@@ -332,7 +391,8 @@ module Sidekiq
|
|
332
391
|
end
|
333
392
|
|
334
393
|
def pollable?
|
335
|
-
|
394
|
+
# there's no point to refreshing the metrics pages every N seconds
|
395
|
+
!(current_path == "" || current_path.index("metrics"))
|
336
396
|
end
|
337
397
|
|
338
398
|
def retry_or_delete_or_kill(job, params)
|
data/lib/sidekiq/web/router.rb
CHANGED
@@ -39,10 +39,13 @@ module Sidekiq
|
|
39
39
|
route(DELETE, path, &block)
|
40
40
|
end
|
41
41
|
|
42
|
-
def route(
|
42
|
+
def route(*methods, path, &block)
|
43
43
|
@routes ||= {GET => [], POST => [], PUT => [], PATCH => [], DELETE => [], HEAD => []}
|
44
44
|
|
45
|
-
|
45
|
+
methods.each do |method|
|
46
|
+
method = method.to_s.upcase
|
47
|
+
@routes[method] << WebRoute.new(method, path, block)
|
48
|
+
end
|
46
49
|
end
|
47
50
|
|
48
51
|
def match(env)
|
data/lib/sidekiq/web.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "erb"
|
4
|
+
require "securerandom"
|
4
5
|
|
5
6
|
require "sidekiq"
|
6
7
|
require "sidekiq/api"
|
@@ -39,14 +40,21 @@ module Sidekiq
|
|
39
40
|
CONTENT_SECURITY_POLICY = "Content-Security-Policy"
|
40
41
|
LOCATION = "Location"
|
41
42
|
X_CASCADE = "X-Cascade"
|
43
|
+
X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options"
|
42
44
|
else
|
43
45
|
CONTENT_LANGUAGE = "content-language"
|
44
46
|
CONTENT_SECURITY_POLICY = "content-security-policy"
|
45
47
|
LOCATION = "location"
|
46
48
|
X_CASCADE = "x-cascade"
|
49
|
+
X_CONTENT_TYPE_OPTIONS = "x-content-type-options"
|
47
50
|
end
|
48
51
|
|
49
52
|
class << self
|
53
|
+
# Forward compatibility with 8.0
|
54
|
+
def configure
|
55
|
+
yield self
|
56
|
+
end
|
57
|
+
|
50
58
|
def settings
|
51
59
|
self
|
52
60
|
end
|
@@ -114,6 +122,7 @@ module Sidekiq
|
|
114
122
|
end
|
115
123
|
|
116
124
|
def call(env)
|
125
|
+
env[:csp_nonce] = SecureRandom.base64(16)
|
117
126
|
app.call(env)
|
118
127
|
end
|
119
128
|
|
@@ -138,7 +147,50 @@ module Sidekiq
|
|
138
147
|
send(:"#{attribute}=", value)
|
139
148
|
end
|
140
149
|
|
141
|
-
|
150
|
+
# Register a class as a Sidekiq Web UI extension. The class should
|
151
|
+
# provide one or more tabs which map to an index route. Options:
|
152
|
+
#
|
153
|
+
# @param extension [Class] Class which contains the HTTP actions, required
|
154
|
+
# @param name [String] the name of the extension, used to namespace assets
|
155
|
+
# @param tab [String | Array] labels(s) of the UI tabs
|
156
|
+
# @param index [String | Array] index route(s) for each tab
|
157
|
+
# @param root_dir [String] directory location to find assets, locales and views, typically `web/` within the gemfile
|
158
|
+
# @param asset_paths [Array] one or more directories under {root}/assets/{name} to be publicly served, e.g. ["js", "css", "img"]
|
159
|
+
# @param cache_for [Integer] amount of time to cache assets, default one day
|
160
|
+
#
|
161
|
+
# TODO name, tab and index will be mandatory in 8.0
|
162
|
+
#
|
163
|
+
# Web extensions will have a root `web/` directory with `locales/`, `assets/`
|
164
|
+
# and `views/` subdirectories.
|
165
|
+
def self.register(extension, name: nil, tab: nil, index: nil, root_dir: nil, cache_for: 86400, asset_paths: nil)
|
166
|
+
tab = Array(tab)
|
167
|
+
index = Array(index)
|
168
|
+
tab.zip(index).each do |tab, index|
|
169
|
+
tabs[tab] = index
|
170
|
+
end
|
171
|
+
if root_dir
|
172
|
+
locdir = File.join(root_dir, "locales")
|
173
|
+
locales << locdir if File.directory?(locdir)
|
174
|
+
|
175
|
+
if asset_paths && name
|
176
|
+
# if you have {root}/assets/{name}/js/scripts.js
|
177
|
+
# and {root}/assets/{name}/css/styles.css
|
178
|
+
# you would pass in:
|
179
|
+
# asset_paths: ["js", "css"]
|
180
|
+
# See script_tag and style_tag in web/helpers.rb
|
181
|
+
assdir = File.join(root_dir, "assets")
|
182
|
+
assurls = Array(asset_paths).map { |x| "/#{name}/#{x}" }
|
183
|
+
assetprops = {
|
184
|
+
urls: assurls,
|
185
|
+
root: assdir,
|
186
|
+
cascade: true
|
187
|
+
}
|
188
|
+
assetprops[:header_rules] = [[:all, {Rack::CACHE_CONTROL => "private, max-age=#{cache_for.to_i}"}]] if cache_for
|
189
|
+
middlewares << [[Rack::Static, assetprops], nil]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
yield self if block_given?
|
142
194
|
extension.registered(WebApplication)
|
143
195
|
end
|
144
196
|
|
@@ -166,7 +218,7 @@ module Sidekiq
|
|
166
218
|
Sidekiq::WebApplication.helpers WebHelpers
|
167
219
|
Sidekiq::WebApplication.helpers Sidekiq::Paginator
|
168
220
|
|
169
|
-
Sidekiq::WebAction.class_eval <<-RUBY,
|
221
|
+
Sidekiq::WebAction.class_eval <<-RUBY, Web::LAYOUT, -1 # standard:disable Style/EvalWithLocation
|
170
222
|
def _render
|
171
223
|
#{ERB.new(File.read(Web::LAYOUT)).src}
|
172
224
|
end
|
data/lib/sidekiq.rb
CHANGED
@@ -32,6 +32,7 @@ require "sidekiq/logger"
|
|
32
32
|
require "sidekiq/client"
|
33
33
|
require "sidekiq/transaction_aware_client"
|
34
34
|
require "sidekiq/job"
|
35
|
+
require "sidekiq/iterable_job"
|
35
36
|
require "sidekiq/worker_compatibility_alias"
|
36
37
|
require "sidekiq/redis_client_adapter"
|
37
38
|
|
@@ -101,18 +102,19 @@ module Sidekiq
|
|
101
102
|
def self.freeze!
|
102
103
|
@frozen = true
|
103
104
|
@config_blocks = nil
|
105
|
+
default_configuration.freeze!
|
104
106
|
end
|
105
107
|
|
106
108
|
# Creates a Sidekiq::Config instance that is more tuned for embedding
|
107
109
|
# within an arbitrary Ruby process. Notably it reduces concurrency by
|
108
110
|
# default so there is less contention for CPU time with other threads.
|
109
111
|
#
|
110
|
-
#
|
112
|
+
# instance = Sidekiq.configure_embed do |config|
|
111
113
|
# config.queues = %w[critical default low]
|
112
114
|
# end
|
113
|
-
#
|
115
|
+
# instance.run
|
114
116
|
# sleep 10
|
115
|
-
#
|
117
|
+
# instance.stop
|
116
118
|
#
|
117
119
|
# NB: it is really easy to overload a Ruby process with threads due to the GIL.
|
118
120
|
# I do not recommend setting concurrency higher than 2-3.
|
data/sidekiq.gemspec
CHANGED
@@ -23,8 +23,9 @@ Gem::Specification.new do |gem|
|
|
23
23
|
"rubygems_mfa_required" => "true"
|
24
24
|
}
|
25
25
|
|
26
|
-
gem.add_dependency "redis-client", ">= 0.
|
26
|
+
gem.add_dependency "redis-client", ">= 0.22.2"
|
27
27
|
gem.add_dependency "connection_pool", ">= 2.3.0"
|
28
28
|
gem.add_dependency "rack", ">= 2.2.4"
|
29
|
-
gem.add_dependency "
|
29
|
+
gem.add_dependency "logger"
|
30
|
+
gem.add_dependency "base64"
|
30
31
|
end
|