sidekiq 6.2.2 → 7.1.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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +299 -11
  3. data/LICENSE.txt +9 -0
  4. data/README.md +45 -32
  5. data/bin/sidekiq +4 -9
  6. data/bin/sidekiqload +207 -117
  7. data/bin/sidekiqmon +4 -1
  8. data/lib/generators/sidekiq/job_generator.rb +57 -0
  9. data/lib/generators/sidekiq/templates/{worker.rb.erb → job.rb.erb} +2 -2
  10. data/lib/generators/sidekiq/templates/{worker_spec.rb.erb → job_spec.rb.erb} +1 -1
  11. data/lib/generators/sidekiq/templates/{worker_test.rb.erb → job_test.rb.erb} +1 -1
  12. data/lib/sidekiq/api.rb +334 -190
  13. data/lib/sidekiq/capsule.rb +127 -0
  14. data/lib/sidekiq/cli.rb +95 -81
  15. data/lib/sidekiq/client.rb +102 -96
  16. data/lib/sidekiq/{util.rb → component.rb} +14 -41
  17. data/lib/sidekiq/config.rb +278 -0
  18. data/lib/sidekiq/deploy.rb +62 -0
  19. data/lib/sidekiq/embedded.rb +61 -0
  20. data/lib/sidekiq/fetch.rb +26 -26
  21. data/lib/sidekiq/job.rb +371 -5
  22. data/lib/sidekiq/job_logger.rb +16 -28
  23. data/lib/sidekiq/job_retry.rb +85 -59
  24. data/lib/sidekiq/job_util.rb +105 -0
  25. data/lib/sidekiq/launcher.rb +106 -94
  26. data/lib/sidekiq/logger.rb +9 -44
  27. data/lib/sidekiq/manager.rb +40 -41
  28. data/lib/sidekiq/metrics/query.rb +153 -0
  29. data/lib/sidekiq/metrics/shared.rb +95 -0
  30. data/lib/sidekiq/metrics/tracking.rb +136 -0
  31. data/lib/sidekiq/middleware/chain.rb +96 -51
  32. data/lib/sidekiq/middleware/current_attributes.rb +95 -0
  33. data/lib/sidekiq/middleware/i18n.rb +6 -4
  34. data/lib/sidekiq/middleware/modules.rb +21 -0
  35. data/lib/sidekiq/monitor.rb +17 -4
  36. data/lib/sidekiq/paginator.rb +17 -9
  37. data/lib/sidekiq/processor.rb +60 -60
  38. data/lib/sidekiq/rails.rb +29 -6
  39. data/lib/sidekiq/redis_client_adapter.rb +96 -0
  40. data/lib/sidekiq/redis_connection.rb +17 -88
  41. data/lib/sidekiq/ring_buffer.rb +29 -0
  42. data/lib/sidekiq/scheduled.rb +101 -44
  43. data/lib/sidekiq/testing/inline.rb +4 -4
  44. data/lib/sidekiq/testing.rb +41 -68
  45. data/lib/sidekiq/transaction_aware_client.rb +44 -0
  46. data/lib/sidekiq/version.rb +2 -1
  47. data/lib/sidekiq/web/action.rb +3 -3
  48. data/lib/sidekiq/web/application.rb +47 -13
  49. data/lib/sidekiq/web/csrf_protection.rb +3 -3
  50. data/lib/sidekiq/web/helpers.rb +36 -33
  51. data/lib/sidekiq/web.rb +10 -17
  52. data/lib/sidekiq/worker_compatibility_alias.rb +13 -0
  53. data/lib/sidekiq.rb +86 -201
  54. data/sidekiq.gemspec +12 -10
  55. data/web/assets/javascripts/application.js +131 -60
  56. data/web/assets/javascripts/base-charts.js +106 -0
  57. data/web/assets/javascripts/chart.min.js +13 -0
  58. data/web/assets/javascripts/chartjs-plugin-annotation.min.js +7 -0
  59. data/web/assets/javascripts/dashboard-charts.js +166 -0
  60. data/web/assets/javascripts/dashboard.js +36 -273
  61. data/web/assets/javascripts/metrics.js +264 -0
  62. data/web/assets/stylesheets/application-dark.css +23 -23
  63. data/web/assets/stylesheets/application-rtl.css +2 -95
  64. data/web/assets/stylesheets/application.css +73 -402
  65. data/web/locales/ar.yml +70 -70
  66. data/web/locales/cs.yml +62 -62
  67. data/web/locales/da.yml +60 -53
  68. data/web/locales/de.yml +65 -65
  69. data/web/locales/el.yml +43 -24
  70. data/web/locales/en.yml +82 -69
  71. data/web/locales/es.yml +68 -68
  72. data/web/locales/fa.yml +65 -65
  73. data/web/locales/fr.yml +81 -67
  74. data/web/locales/gd.yml +99 -0
  75. data/web/locales/he.yml +65 -64
  76. data/web/locales/hi.yml +59 -59
  77. data/web/locales/it.yml +53 -53
  78. data/web/locales/ja.yml +73 -68
  79. data/web/locales/ko.yml +52 -52
  80. data/web/locales/lt.yml +66 -66
  81. data/web/locales/nb.yml +61 -61
  82. data/web/locales/nl.yml +52 -52
  83. data/web/locales/pl.yml +45 -45
  84. data/web/locales/pt-br.yml +63 -55
  85. data/web/locales/pt.yml +51 -51
  86. data/web/locales/ru.yml +67 -66
  87. data/web/locales/sv.yml +53 -53
  88. data/web/locales/ta.yml +60 -60
  89. data/web/locales/uk.yml +62 -61
  90. data/web/locales/ur.yml +64 -64
  91. data/web/locales/vi.yml +67 -67
  92. data/web/locales/zh-cn.yml +43 -16
  93. data/web/locales/zh-tw.yml +42 -8
  94. data/web/views/_footer.erb +6 -3
  95. data/web/views/_job_info.erb +18 -2
  96. data/web/views/_metrics_period_select.erb +12 -0
  97. data/web/views/_nav.erb +1 -1
  98. data/web/views/_paging.erb +2 -0
  99. data/web/views/_poll_link.erb +3 -6
  100. data/web/views/_summary.erb +7 -7
  101. data/web/views/busy.erb +44 -28
  102. data/web/views/dashboard.erb +44 -12
  103. data/web/views/layout.erb +1 -1
  104. data/web/views/metrics.erb +82 -0
  105. data/web/views/metrics_for_job.erb +68 -0
  106. data/web/views/morgue.erb +5 -9
  107. data/web/views/queue.erb +24 -24
  108. data/web/views/queues.erb +4 -2
  109. data/web/views/retries.erb +5 -9
  110. data/web/views/scheduled.erb +12 -13
  111. metadata +62 -31
  112. data/LICENSE +0 -9
  113. data/lib/generators/sidekiq/worker_generator.rb +0 -57
  114. data/lib/sidekiq/delay.rb +0 -41
  115. data/lib/sidekiq/exception_handler.rb +0 -27
  116. data/lib/sidekiq/extensions/action_mailer.rb +0 -48
  117. data/lib/sidekiq/extensions/active_record.rb +0 -43
  118. data/lib/sidekiq/extensions/class_methods.rb +0 -43
  119. data/lib/sidekiq/extensions/generic_proxy.rb +0 -33
  120. data/lib/sidekiq/worker.rb +0 -244
@@ -1,244 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq/client"
4
-
5
- module Sidekiq
6
- ##
7
- # Include this module in your worker class and you can easily create
8
- # asynchronous jobs:
9
- #
10
- # class HardWorker
11
- # include Sidekiq::Worker
12
- #
13
- # def perform(*args)
14
- # # do some work
15
- # end
16
- # end
17
- #
18
- # Then in your Rails app, you can do this:
19
- #
20
- # HardWorker.perform_async(1, 2, 3)
21
- #
22
- # Note that perform_async is a class method, perform is an instance method.
23
- module Worker
24
- ##
25
- # The Options module is extracted so we can include it in ActiveJob::Base
26
- # and allow native AJs to configure Sidekiq features/internals.
27
- module Options
28
- def self.included(base)
29
- base.extend(ClassMethods)
30
- base.sidekiq_class_attribute :sidekiq_options_hash
31
- base.sidekiq_class_attribute :sidekiq_retry_in_block
32
- base.sidekiq_class_attribute :sidekiq_retries_exhausted_block
33
- end
34
-
35
- module ClassMethods
36
- ACCESSOR_MUTEX = Mutex.new
37
-
38
- ##
39
- # Allows customization for this type of Worker.
40
- # Legal options:
41
- #
42
- # queue - name of queue to use for this job type, default *default*
43
- # retry - enable retries for this Worker in case of error during execution,
44
- # *true* to use the default or *Integer* count
45
- # backtrace - whether to save any error backtrace in the retry payload to display in web UI,
46
- # can be true, false or an integer number of lines to save, default *false*
47
- #
48
- # In practice, any option is allowed. This is the main mechanism to configure the
49
- # options for a specific job.
50
- def sidekiq_options(opts = {})
51
- opts = opts.transform_keys(&:to_s) # stringify
52
- self.sidekiq_options_hash = get_sidekiq_options.merge(opts)
53
- end
54
-
55
- def sidekiq_retry_in(&block)
56
- self.sidekiq_retry_in_block = block
57
- end
58
-
59
- def sidekiq_retries_exhausted(&block)
60
- self.sidekiq_retries_exhausted_block = block
61
- end
62
-
63
- def get_sidekiq_options # :nodoc:
64
- self.sidekiq_options_hash ||= Sidekiq.default_worker_options
65
- end
66
-
67
- def sidekiq_class_attribute(*attrs)
68
- instance_reader = true
69
- instance_writer = true
70
-
71
- attrs.each do |name|
72
- synchronized_getter = "__synchronized_#{name}"
73
-
74
- singleton_class.instance_eval do
75
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
76
- end
77
-
78
- define_singleton_method(synchronized_getter) { nil }
79
- singleton_class.class_eval do
80
- private(synchronized_getter)
81
- end
82
-
83
- define_singleton_method(name) { ACCESSOR_MUTEX.synchronize { send synchronized_getter } }
84
-
85
- ivar = "@#{name}"
86
-
87
- singleton_class.instance_eval do
88
- m = "#{name}="
89
- undef_method(m) if method_defined?(m) || private_method_defined?(m)
90
- end
91
- define_singleton_method("#{name}=") do |val|
92
- singleton_class.class_eval do
93
- ACCESSOR_MUTEX.synchronize do
94
- undef_method(synchronized_getter) if method_defined?(synchronized_getter) || private_method_defined?(synchronized_getter)
95
- define_method(synchronized_getter) { val }
96
- end
97
- end
98
-
99
- if singleton_class?
100
- class_eval do
101
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
102
- define_method(name) do
103
- if instance_variable_defined? ivar
104
- instance_variable_get ivar
105
- else
106
- singleton_class.send name
107
- end
108
- end
109
- end
110
- end
111
- val
112
- end
113
-
114
- if instance_reader
115
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
116
- define_method(name) do
117
- if instance_variable_defined?(ivar)
118
- instance_variable_get ivar
119
- else
120
- self.class.public_send name
121
- end
122
- end
123
- end
124
-
125
- if instance_writer
126
- m = "#{name}="
127
- undef_method(m) if method_defined?(m) || private_method_defined?(m)
128
- attr_writer name
129
- end
130
- end
131
- end
132
- end
133
- end
134
-
135
- attr_accessor :jid
136
-
137
- def self.included(base)
138
- raise ArgumentError, "Sidekiq::Worker cannot be included in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" }
139
-
140
- base.include(Options)
141
- base.extend(ClassMethods)
142
- end
143
-
144
- def logger
145
- Sidekiq.logger
146
- end
147
-
148
- # This helper class encapsulates the set options for `set`, e.g.
149
- #
150
- # SomeWorker.set(queue: 'foo').perform_async(....)
151
- #
152
- class Setter
153
- def initialize(klass, opts)
154
- @klass = klass
155
- @opts = opts
156
- end
157
-
158
- def set(options)
159
- @opts.merge!(options)
160
- self
161
- end
162
-
163
- def perform_async(*args)
164
- @klass.client_push(@opts.merge("args" => args, "class" => @klass))
165
- end
166
-
167
- # +interval+ must be a timestamp, numeric or something that acts
168
- # numeric (like an activesupport time interval).
169
- def perform_in(interval, *args)
170
- int = interval.to_f
171
- now = Time.now.to_f
172
- ts = (int < 1_000_000_000 ? now + int : int)
173
-
174
- payload = @opts.merge("class" => @klass, "args" => args)
175
- # Optimization to enqueue something now that is scheduled to go out now or in the past
176
- payload["at"] = ts if ts > now
177
- @klass.client_push(payload)
178
- end
179
- alias_method :perform_at, :perform_in
180
- end
181
-
182
- module ClassMethods
183
- def delay(*args)
184
- raise ArgumentError, "Do not call .delay on a Sidekiq::Worker class, call .perform_async"
185
- end
186
-
187
- def delay_for(*args)
188
- raise ArgumentError, "Do not call .delay_for on a Sidekiq::Worker class, call .perform_in"
189
- end
190
-
191
- def delay_until(*args)
192
- raise ArgumentError, "Do not call .delay_until on a Sidekiq::Worker class, call .perform_at"
193
- end
194
-
195
- def set(options)
196
- Setter.new(self, options)
197
- end
198
-
199
- def perform_async(*args)
200
- client_push("class" => self, "args" => args)
201
- end
202
-
203
- # +interval+ must be a timestamp, numeric or something that acts
204
- # numeric (like an activesupport time interval).
205
- def perform_in(interval, *args)
206
- int = interval.to_f
207
- now = Time.now.to_f
208
- ts = (int < 1_000_000_000 ? now + int : int)
209
-
210
- item = {"class" => self, "args" => args}
211
-
212
- # Optimization to enqueue something now that is scheduled to go out now or in the past
213
- item["at"] = ts if ts > now
214
-
215
- client_push(item)
216
- end
217
- alias_method :perform_at, :perform_in
218
-
219
- ##
220
- # Allows customization for this type of Worker.
221
- # Legal options:
222
- #
223
- # queue - use a named queue for this Worker, default 'default'
224
- # retry - enable the RetryJobs middleware for this Worker, *true* to use the default
225
- # or *Integer* count
226
- # backtrace - whether to save any error backtrace in the retry payload to display in web UI,
227
- # can be true, false or an integer number of lines to save, default *false*
228
- # pool - use the given Redis connection pool to push this type of job to a given shard.
229
- #
230
- # In practice, any option is allowed. This is the main mechanism to configure the
231
- # options for a specific job.
232
- def sidekiq_options(opts = {})
233
- super
234
- end
235
-
236
- def client_push(item) # :nodoc:
237
- pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options["pool"] || Sidekiq.redis_pool
238
- stringified_item = item.transform_keys(&:to_s)
239
-
240
- Sidekiq::Client.new(pool).push(stringified_item)
241
- end
242
- end
243
- end
244
- end