sidekiq 7.3.9 → 8.0.0.beta1

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +21 -4
  3. data/README.md +16 -13
  4. data/bin/sidekiqload +10 -10
  5. data/bin/webload +69 -0
  6. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +5 -5
  7. data/lib/sidekiq/api.rb +108 -36
  8. data/lib/sidekiq/capsule.rb +1 -1
  9. data/lib/sidekiq/cli.rb +15 -19
  10. data/lib/sidekiq/client.rb +13 -16
  11. data/lib/sidekiq/component.rb +30 -2
  12. data/lib/sidekiq/config.rb +18 -15
  13. data/lib/sidekiq/embedded.rb +1 -0
  14. data/lib/sidekiq/job/iterable.rb +2 -4
  15. data/lib/sidekiq/job_retry.rb +2 -2
  16. data/lib/sidekiq/job_util.rb +5 -1
  17. data/lib/sidekiq/launcher.rb +1 -1
  18. data/lib/sidekiq/logger.rb +6 -10
  19. data/lib/sidekiq/manager.rb +0 -1
  20. data/lib/sidekiq/metrics/query.rb +1 -3
  21. data/lib/sidekiq/middleware/current_attributes.rb +5 -17
  22. data/lib/sidekiq/paginator.rb +8 -1
  23. data/lib/sidekiq/processor.rb +21 -14
  24. data/lib/sidekiq/profiler.rb +59 -0
  25. data/lib/sidekiq/redis_client_adapter.rb +0 -1
  26. data/lib/sidekiq/testing.rb +2 -2
  27. data/lib/sidekiq/version.rb +2 -2
  28. data/lib/sidekiq/web/action.rb +101 -85
  29. data/lib/sidekiq/web/application.rb +339 -333
  30. data/lib/sidekiq/web/config.rb +116 -0
  31. data/lib/sidekiq/web/helpers.rb +40 -15
  32. data/lib/sidekiq/web/router.rb +60 -76
  33. data/lib/sidekiq/web.rb +51 -156
  34. data/sidekiq.gemspec +5 -4
  35. data/web/assets/javascripts/application.js +6 -13
  36. data/web/assets/javascripts/base-charts.js +30 -18
  37. data/web/assets/javascripts/metrics.js +1 -1
  38. data/web/assets/stylesheets/style.css +750 -0
  39. data/web/locales/ar.yml +1 -0
  40. data/web/locales/cs.yml +1 -0
  41. data/web/locales/da.yml +1 -0
  42. data/web/locales/de.yml +1 -0
  43. data/web/locales/el.yml +1 -0
  44. data/web/locales/en.yml +6 -0
  45. data/web/locales/es.yml +24 -2
  46. data/web/locales/fa.yml +1 -0
  47. data/web/locales/fr.yml +1 -0
  48. data/web/locales/gd.yml +1 -0
  49. data/web/locales/he.yml +1 -0
  50. data/web/locales/hi.yml +1 -0
  51. data/web/locales/it.yml +1 -0
  52. data/web/locales/ja.yml +1 -0
  53. data/web/locales/ko.yml +1 -0
  54. data/web/locales/lt.yml +1 -0
  55. data/web/locales/nb.yml +1 -0
  56. data/web/locales/nl.yml +1 -0
  57. data/web/locales/pl.yml +1 -0
  58. data/web/locales/{pt-br.yml → pt-BR.yml} +2 -1
  59. data/web/locales/pt.yml +1 -0
  60. data/web/locales/ru.yml +1 -0
  61. data/web/locales/sv.yml +1 -0
  62. data/web/locales/ta.yml +1 -0
  63. data/web/locales/tr.yml +1 -0
  64. data/web/locales/uk.yml +1 -0
  65. data/web/locales/ur.yml +1 -0
  66. data/web/locales/vi.yml +1 -0
  67. data/web/locales/{zh-cn.yml → zh-CN.yml} +85 -73
  68. data/web/locales/{zh-tw.yml → zh-TW.yml} +2 -1
  69. data/web/views/_footer.erb +31 -33
  70. data/web/views/_job_info.erb +91 -89
  71. data/web/views/_metrics_period_select.erb +1 -1
  72. data/web/views/_nav.erb +14 -21
  73. data/web/views/_paging.erb +23 -21
  74. data/web/views/_poll_link.erb +2 -2
  75. data/web/views/_summary.erb +16 -16
  76. data/web/views/busy.erb +124 -122
  77. data/web/views/dashboard.erb +61 -66
  78. data/web/views/dead.erb +31 -27
  79. data/web/views/filtering.erb +3 -3
  80. data/web/views/layout.erb +5 -21
  81. data/web/views/metrics.erb +83 -80
  82. data/web/views/metrics_for_job.erb +39 -42
  83. data/web/views/morgue.erb +61 -70
  84. data/web/views/profiles.erb +43 -0
  85. data/web/views/queue.erb +54 -52
  86. data/web/views/queues.erb +43 -41
  87. data/web/views/retries.erb +66 -75
  88. data/web/views/retry.erb +32 -27
  89. data/web/views/scheduled.erb +58 -54
  90. data/web/views/scheduled_job_info.erb +1 -1
  91. metadata +31 -18
  92. data/web/assets/stylesheets/application-dark.css +0 -147
  93. data/web/assets/stylesheets/application-rtl.css +0 -163
  94. data/web/assets/stylesheets/application.css +0 -759
  95. data/web/assets/stylesheets/bootstrap-rtl.min.css +0 -9
  96. data/web/assets/stylesheets/bootstrap.css +0 -5
  97. data/web/views/_status.erb +0 -4
@@ -1,115 +1,131 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Sidekiq
4
- class WebAction
5
- RACK_SESSION = "rack.session"
6
-
7
- attr_accessor :env, :block, :type
3
+ require "erb"
8
4
 
9
- def settings
10
- Web.settings
11
- end
5
+ module Sidekiq
6
+ class Web
7
+ ##
8
+ # These instance methods are available to all executing ERB
9
+ # templates.
10
+ class Action
11
+ attr_accessor :env, :block
12
+
13
+ def initialize(env, block)
14
+ @_erb = false
15
+ @env = env
16
+ @block = block
17
+ end
12
18
 
13
- def request
14
- @request ||= ::Rack::Request.new(env)
15
- end
19
+ def config
20
+ env[:web_config]
21
+ end
16
22
 
17
- def halt(res)
18
- throw :halt, [res, {Rack::CONTENT_TYPE => "text/plain"}, [res.to_s]]
19
- end
23
+ def request
24
+ @request ||= ::Rack::Request.new(env)
25
+ end
20
26
 
21
- def redirect(location)
22
- throw :halt, [302, {Web::LOCATION => "#{request.base_url}#{location}"}, []]
23
- end
27
+ def halt(res)
28
+ throw :halt, [res, {"content-type" => "text/plain"}, [res.to_s]]
29
+ end
24
30
 
25
- def reload_page
26
- current_location = request.referer.gsub(request.base_url, "")
27
- redirect current_location
28
- end
31
+ # external redirect
32
+ def redirect_to(url)
33
+ throw :halt, [302, {"Location" => url}, []]
34
+ end
29
35
 
30
- # deprecated, will warn in 8.0
31
- def params
32
- indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
36
+ # internal redirect
37
+ def redirect(location)
38
+ throw :halt, [302, {"Location" => "#{request.base_url}#{location}"}, []]
39
+ end
33
40
 
34
- indifferent_hash.merge! request.params
35
- route_params.each { |k, v| indifferent_hash[k.to_s] = v }
41
+ def reload_page
42
+ current_location = request.referer.gsub(request.base_url, "")
43
+ redirect current_location
44
+ end
36
45
 
37
- indifferent_hash
38
- end
46
+ # stuff after ? or form input
47
+ # uses String keys, no Symbols!
48
+ def url_params(key)
49
+ warn { "URL parameter `#{key}` should be accessed via String, not Symbol (at #{caller(3..3).first})" } if key.is_a?(Symbol)
50
+ request.params[key.to_s]
51
+ end
39
52
 
40
- # Use like `url_params("page")` within your action blocks
41
- def url_params(key)
42
- request.params[key]
43
- end
53
+ # variables embedded in path, `/metrics/:name`
54
+ # uses Symbol keys, no Strings!
55
+ def route_params(key)
56
+ warn { "Route parameter `#{key}` should be accessed via Symbol, not String (at #{caller(3..3).first})" } if key.is_a?(String)
57
+ env["rack.route_params"][key.to_sym]
58
+ end
44
59
 
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]
60
+ def params
61
+ warn { "Direct access to Rack parameters is discouraged, use `url_params` or `route_params` (at #{caller(3..3).first})" }
62
+ request.params
52
63
  end
53
- end
54
64
 
55
- def session
56
- env[RACK_SESSION]
57
- end
65
+ def session
66
+ env["rack.session"]
67
+ end
58
68
 
59
- def erb(content, options = {})
60
- if content.is_a? Symbol
61
- unless respond_to?(:"_erb_#{content}")
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
69
- def _erb_#{content}
70
- #{src}
71
- end
72
- RUBY
69
+ def erb(content, options = {})
70
+ if content.is_a? Symbol
71
+ unless respond_to?(:"_erb_#{content}")
72
+ views = options[:views] || Web.views
73
+ filename = "#{views}/#{content}.erb"
74
+ src = ERB.new(File.read(filename)).src
75
+
76
+ # Need to use lineno less by 1 because erb generates a
77
+ # comment before the source code.
78
+ Action.class_eval <<-RUBY, filename, -1 # standard:disable Style/EvalWithLocation
79
+ def _erb_#{content}
80
+ #{src}
81
+ end
82
+ RUBY
83
+ end
73
84
  end
74
- end
75
85
 
76
- if @_erb
77
- _erb(content, options[:locals])
78
- else
79
- @_erb = true
80
- content = _erb(content, options[:locals])
86
+ if @_erb
87
+ _erb(content, options[:locals])
88
+ else
89
+ @_erb = true
90
+ content = _erb(content, options[:locals])
81
91
 
82
- _render { content }
92
+ _render { content }
93
+ end
83
94
  end
84
- end
85
95
 
86
- def render(engine, content, options = {})
87
- raise "Only erb templates are supported" if engine != :erb
96
+ def render(engine, content, options = {})
97
+ raise "Only erb templates are supported" if engine != :erb
88
98
 
89
- erb(content, options)
90
- end
99
+ erb(content, options)
100
+ end
91
101
 
92
- def json(payload)
93
- [200, {Rack::CONTENT_TYPE => "application/json", Rack::CACHE_CONTROL => "private, no-store"}, [Sidekiq.dump_json(payload)]]
94
- end
102
+ def json(payload)
103
+ [200,
104
+ {"content-type" => "application/json", "cache-control" => "private, no-store"},
105
+ [Sidekiq.dump_json(payload)]]
106
+ end
95
107
 
96
- def initialize(env, block)
97
- @_erb = false
98
- @env = env
99
- @block = block
100
- @files ||= {}
101
- end
108
+ private
102
109
 
103
- private
110
+ def warn
111
+ Sidekiq.logger.warn yield
112
+ end
104
113
 
105
- def _erb(file, locals)
106
- locals&.each { |k, v| define_singleton_method(k) { v } unless singleton_methods.include? k }
114
+ def _erb(file, locals)
115
+ locals&.each { |k, v| define_singleton_method(k) { v } unless singleton_methods.include? k }
107
116
 
108
- if file.is_a?(String)
109
- ERB.new(file).result(binding)
110
- else
111
- send(:"_erb_#{file}")
117
+ if file.is_a?(String)
118
+ ERB.new(file).result(binding)
119
+ else
120
+ send(:"_erb_#{file}")
121
+ end
112
122
  end
123
+
124
+ class_eval <<-RUBY, ::Sidekiq::Web::LAYOUT, -1 # standard:disable Style/EvalWithLocation
125
+ def _render
126
+ #{ERB.new(File.read(::Sidekiq::Web::LAYOUT)).src}
127
+ end
128
+ RUBY
113
129
  end
114
130
  end
115
131
  end