sidekiq 7.1.6 → 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 +184 -0
- data/README.md +3 -3
- 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 +21 -1
- data/lib/sidekiq/component.rb +22 -0
- data/lib/sidekiq/config.rb +31 -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 +19 -3
- data/lib/sidekiq/redis_client_adapter.rb +24 -5
- data/lib/sidekiq/redis_connection.rb +36 -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 +14 -8
- 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 +53 -64
- data/lib/sidekiq/web/csrf_protection.rb +8 -5
- data/lib/sidekiq/web/helpers.rb +73 -27
- 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 +3 -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 +4 -5
- 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 +33 -13
@@ -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,54 +350,16 @@ module Sidekiq
|
|
328
350
|
json Sidekiq::Stats.new.queues
|
329
351
|
end
|
330
352
|
|
331
|
-
|
332
|
-
|
333
|
-
get "/filter/retries" do
|
334
|
-
x = params[:substr]
|
335
|
-
return redirect "#{root_path}retries" unless x && x != ""
|
336
|
-
|
337
|
-
@retries = search(Sidekiq::RetrySet.new, params[:substr])
|
338
|
-
erb :retries
|
339
|
-
end
|
340
|
-
|
341
|
-
post "/filter/retries" do
|
342
|
-
x = params[:substr]
|
343
|
-
return redirect "#{root_path}retries" unless x && x != ""
|
344
|
-
|
345
|
-
@retries = search(Sidekiq::RetrySet.new, params[:substr])
|
346
|
-
erb :retries
|
347
|
-
end
|
348
|
-
|
349
|
-
get "/filter/scheduled" do
|
350
|
-
x = params[:substr]
|
351
|
-
return redirect "#{root_path}scheduled" unless x && x != ""
|
352
|
-
|
353
|
-
@scheduled = search(Sidekiq::ScheduledSet.new, params[:substr])
|
354
|
-
erb :scheduled
|
355
|
-
end
|
356
|
-
|
357
|
-
post "/filter/scheduled" do
|
358
|
-
x = params[:substr]
|
359
|
-
return redirect "#{root_path}scheduled" unless x && x != ""
|
360
|
-
|
361
|
-
@scheduled = search(Sidekiq::ScheduledSet.new, params[:substr])
|
362
|
-
erb :scheduled
|
363
|
-
end
|
364
|
-
|
365
|
-
get "/filter/dead" do
|
366
|
-
x = params[:substr]
|
367
|
-
return redirect "#{root_path}morgue" unless x && x != ""
|
353
|
+
post "/change_locale" do
|
354
|
+
locale = params["locale"]
|
368
355
|
|
369
|
-
|
370
|
-
|
371
|
-
|
356
|
+
match = available_locales.find { |available|
|
357
|
+
locale == available
|
358
|
+
}
|
372
359
|
|
373
|
-
|
374
|
-
x = params[:substr]
|
375
|
-
return redirect "#{root_path}morgue" unless x && x != ""
|
360
|
+
session[:locale] = match if match
|
376
361
|
|
377
|
-
|
378
|
-
erb :morgue
|
362
|
+
reload_page
|
379
363
|
end
|
380
364
|
|
381
365
|
def call(env)
|
@@ -400,13 +384,18 @@ module Sidekiq
|
|
400
384
|
Rack::CONTENT_TYPE => "text/html",
|
401
385
|
Rack::CACHE_CONTROL => "private, no-store",
|
402
386
|
Web::CONTENT_LANGUAGE => action.locale,
|
403
|
-
Web::CONTENT_SECURITY_POLICY =>
|
387
|
+
Web::CONTENT_SECURITY_POLICY => process_csp(env, CSP_HEADER_TEMPLATE),
|
388
|
+
Web::X_CONTENT_TYPE_OPTIONS => "nosniff"
|
404
389
|
}
|
405
390
|
# we'll let Rack calculate Content-Length for us.
|
406
391
|
[200, headers, [resp]]
|
407
392
|
end
|
408
393
|
end
|
409
394
|
|
395
|
+
def process_csp(env, input)
|
396
|
+
input.gsub("!placeholder!", env[:csp_nonce])
|
397
|
+
end
|
398
|
+
|
410
399
|
def self.helpers(mod = nil, &block)
|
411
400
|
if block
|
412
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,19 +77,19 @@ 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)
|
@@ -64,7 +111,7 @@ module Sidekiq
|
|
64
111
|
if within.nil?
|
65
112
|
::Rack::Utils.escape_html(jid)
|
66
113
|
else
|
67
|
-
"<a href='#{root_path}
|
114
|
+
"<a href='#{root_path}#{within}?substr=#{jid}'>#{::Rack::Utils.escape_html(jid)}</a>"
|
68
115
|
end
|
69
116
|
end
|
70
117
|
|
@@ -117,7 +164,10 @@ module Sidekiq
|
|
117
164
|
#
|
118
165
|
# Inspiration taken from https://github.com/iain/http_accept_language/blob/master/lib/http_accept_language/parser.rb
|
119
166
|
def locale
|
120
|
-
|
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
|
121
171
|
matched_locale = user_preferred_languages.map { |preferred|
|
122
172
|
preferred_language = preferred.split("-", 2).first
|
123
173
|
|
@@ -134,7 +184,8 @@ module Sidekiq
|
|
134
184
|
|
135
185
|
# sidekiq/sidekiq#3243
|
136
186
|
def unfiltered?
|
137
|
-
|
187
|
+
s = url_params("substr")
|
188
|
+
yield unless s && s.size > 0
|
138
189
|
end
|
139
190
|
|
140
191
|
def get_locale
|
@@ -259,6 +310,10 @@ module Sidekiq
|
|
259
310
|
"<input type='hidden' name='authenticity_token' value='#{env[:csrf_token]}'/>"
|
260
311
|
end
|
261
312
|
|
313
|
+
def csp_nonce
|
314
|
+
env[:csp_nonce]
|
315
|
+
end
|
316
|
+
|
262
317
|
def to_display(arg)
|
263
318
|
arg.inspect
|
264
319
|
rescue
|
@@ -292,27 +347,17 @@ module Sidekiq
|
|
292
347
|
elsif rss_kb < 10_000_000
|
293
348
|
"#{number_with_delimiter((rss_kb / 1024.0).to_i)} MB"
|
294
349
|
else
|
295
|
-
"#{number_with_delimiter((rss_kb / (1024.0 * 1024.0))
|
350
|
+
"#{number_with_delimiter((rss_kb / (1024.0 * 1024.0)), precision: 1)} GB"
|
296
351
|
end
|
297
352
|
end
|
298
353
|
|
299
|
-
def number_with_delimiter(number)
|
300
|
-
|
301
|
-
|
302
|
-
begin
|
303
|
-
Float(number)
|
304
|
-
rescue ArgumentError, TypeError
|
305
|
-
return number
|
306
|
-
end
|
307
|
-
|
308
|
-
options = {delimiter: ",", separator: "."}
|
309
|
-
parts = number.to_s.to_str.split(".")
|
310
|
-
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
|
311
|
-
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>)
|
312
357
|
end
|
313
358
|
|
314
359
|
def h(text)
|
315
|
-
::Rack::Utils.escape_html(text)
|
360
|
+
::Rack::Utils.escape_html(text.to_s)
|
316
361
|
rescue ArgumentError => e
|
317
362
|
raise unless e.message.eql?("invalid byte sequence in UTF-8")
|
318
363
|
text.encode!("UTF-16", "UTF-8", invalid: :replace, replace: "").encode!("UTF-8", "UTF-16")
|
@@ -346,7 +391,8 @@ module Sidekiq
|
|
346
391
|
end
|
347
392
|
|
348
393
|
def pollable?
|
349
|
-
|
394
|
+
# there's no point to refreshing the metrics pages every N seconds
|
395
|
+
!(current_path == "" || current_path.index("metrics"))
|
350
396
|
end
|
351
397
|
|
352
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
|
@@ -33,6 +33,8 @@ function addListeners() {
|
|
33
33
|
|
34
34
|
addShiftClickListeners()
|
35
35
|
updateFuzzyTimes();
|
36
|
+
updateNumbers();
|
37
|
+
updateProgressBars();
|
36
38
|
setLivePollFromUrl();
|
37
39
|
|
38
40
|
var buttons = document.querySelectorAll(".live-poll");
|
@@ -46,6 +48,8 @@ function addListeners() {
|
|
46
48
|
scheduleLivePoll();
|
47
49
|
}
|
48
50
|
}
|
51
|
+
|
52
|
+
document.getElementById("locale-select").addEventListener("change", updateLocale);
|
49
53
|
}
|
50
54
|
|
51
55
|
function addPollingListeners(_event) {
|
@@ -102,6 +106,20 @@ function updateFuzzyTimes() {
|
|
102
106
|
t.cancel();
|
103
107
|
}
|
104
108
|
|
109
|
+
function updateNumbers() {
|
110
|
+
document.querySelectorAll("[data-nwp]").forEach(node => {
|
111
|
+
let number = parseFloat(node.textContent);
|
112
|
+
let precision = parseInt(node.dataset["nwp"] || 0);
|
113
|
+
if (typeof number === "number") {
|
114
|
+
let formatted = number.toLocaleString(undefined, {
|
115
|
+
minimumFractionDigits: precision,
|
116
|
+
maximumFractionDigits: precision,
|
117
|
+
});
|
118
|
+
node.textContent = formatted;
|
119
|
+
}
|
120
|
+
});
|
121
|
+
}
|
122
|
+
|
105
123
|
function setLivePollFromUrl() {
|
106
124
|
var url_params = new URL(window.location.href).searchParams
|
107
125
|
|
@@ -160,3 +178,11 @@ function replacePage(text) {
|
|
160
178
|
function showError(error) {
|
161
179
|
console.error(error)
|
162
180
|
}
|
181
|
+
|
182
|
+
function updateLocale(event) {
|
183
|
+
event.target.form.submit();
|
184
|
+
}
|
185
|
+
|
186
|
+
function updateProgressBars() {
|
187
|
+
document.querySelectorAll('.progress-bar').forEach(bar => { bar.style.width = bar.dataset.width + "%"})
|
188
|
+
}
|