sidekiq 6.5.1 → 7.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +376 -12
  3. data/README.md +43 -35
  4. data/bin/multi_queue_bench +271 -0
  5. data/bin/sidekiq +3 -8
  6. data/bin/sidekiqload +213 -118
  7. data/bin/sidekiqmon +3 -0
  8. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +88 -0
  9. data/lib/generators/sidekiq/job_generator.rb +2 -0
  10. data/lib/sidekiq/api.rb +378 -173
  11. data/lib/sidekiq/capsule.rb +132 -0
  12. data/lib/sidekiq/cli.rb +61 -63
  13. data/lib/sidekiq/client.rb +89 -40
  14. data/lib/sidekiq/component.rb +6 -2
  15. data/lib/sidekiq/config.rb +305 -0
  16. data/lib/sidekiq/deploy.rb +64 -0
  17. data/lib/sidekiq/embedded.rb +63 -0
  18. data/lib/sidekiq/fetch.rb +11 -14
  19. data/lib/sidekiq/iterable_job.rb +55 -0
  20. data/lib/sidekiq/job/interrupt_handler.rb +24 -0
  21. data/lib/sidekiq/job/iterable/active_record_enumerator.rb +53 -0
  22. data/lib/sidekiq/job/iterable/csv_enumerator.rb +47 -0
  23. data/lib/sidekiq/job/iterable/enumerators.rb +135 -0
  24. data/lib/sidekiq/job/iterable.rb +294 -0
  25. data/lib/sidekiq/job.rb +382 -10
  26. data/lib/sidekiq/job_logger.rb +8 -7
  27. data/lib/sidekiq/job_retry.rb +89 -46
  28. data/lib/sidekiq/job_util.rb +53 -15
  29. data/lib/sidekiq/launcher.rb +77 -69
  30. data/lib/sidekiq/logger.rb +2 -27
  31. data/lib/sidekiq/manager.rb +9 -11
  32. data/lib/sidekiq/metrics/query.rb +158 -0
  33. data/lib/sidekiq/metrics/shared.rb +106 -0
  34. data/lib/sidekiq/metrics/tracking.rb +148 -0
  35. data/lib/sidekiq/middleware/chain.rb +84 -48
  36. data/lib/sidekiq/middleware/current_attributes.rb +87 -20
  37. data/lib/sidekiq/middleware/modules.rb +2 -0
  38. data/lib/sidekiq/monitor.rb +19 -5
  39. data/lib/sidekiq/paginator.rb +11 -3
  40. data/lib/sidekiq/processor.rb +67 -56
  41. data/lib/sidekiq/rails.rb +22 -16
  42. data/lib/sidekiq/redis_client_adapter.rb +31 -71
  43. data/lib/sidekiq/redis_connection.rb +44 -117
  44. data/lib/sidekiq/ring_buffer.rb +2 -0
  45. data/lib/sidekiq/scheduled.rb +62 -35
  46. data/lib/sidekiq/systemd.rb +2 -0
  47. data/lib/sidekiq/testing.rb +37 -46
  48. data/lib/sidekiq/transaction_aware_client.rb +11 -5
  49. data/lib/sidekiq/version.rb +6 -1
  50. data/lib/sidekiq/web/action.rb +15 -5
  51. data/lib/sidekiq/web/application.rb +94 -24
  52. data/lib/sidekiq/web/csrf_protection.rb +10 -7
  53. data/lib/sidekiq/web/helpers.rb +118 -45
  54. data/lib/sidekiq/web/router.rb +5 -2
  55. data/lib/sidekiq/web.rb +67 -15
  56. data/lib/sidekiq/worker_compatibility_alias.rb +13 -0
  57. data/lib/sidekiq.rb +78 -266
  58. data/sidekiq.gemspec +12 -10
  59. data/web/assets/javascripts/application.js +46 -1
  60. data/web/assets/javascripts/base-charts.js +106 -0
  61. data/web/assets/javascripts/chart.min.js +13 -0
  62. data/web/assets/javascripts/chartjs-plugin-annotation.min.js +7 -0
  63. data/web/assets/javascripts/dashboard-charts.js +192 -0
  64. data/web/assets/javascripts/dashboard.js +11 -250
  65. data/web/assets/javascripts/metrics.js +298 -0
  66. data/web/assets/stylesheets/application-dark.css +4 -0
  67. data/web/assets/stylesheets/application-rtl.css +10 -89
  68. data/web/assets/stylesheets/application.css +98 -295
  69. data/web/locales/ar.yml +70 -70
  70. data/web/locales/cs.yml +62 -62
  71. data/web/locales/da.yml +60 -53
  72. data/web/locales/de.yml +65 -65
  73. data/web/locales/el.yml +43 -24
  74. data/web/locales/en.yml +83 -69
  75. data/web/locales/es.yml +68 -68
  76. data/web/locales/fa.yml +65 -65
  77. data/web/locales/fr.yml +80 -67
  78. data/web/locales/gd.yml +98 -0
  79. data/web/locales/he.yml +65 -64
  80. data/web/locales/hi.yml +59 -59
  81. data/web/locales/it.yml +85 -54
  82. data/web/locales/ja.yml +72 -68
  83. data/web/locales/ko.yml +52 -52
  84. data/web/locales/lt.yml +66 -66
  85. data/web/locales/nb.yml +61 -61
  86. data/web/locales/nl.yml +52 -52
  87. data/web/locales/pl.yml +45 -45
  88. data/web/locales/pt-br.yml +78 -69
  89. data/web/locales/pt.yml +51 -51
  90. data/web/locales/ru.yml +67 -66
  91. data/web/locales/sv.yml +53 -53
  92. data/web/locales/ta.yml +60 -60
  93. data/web/locales/tr.yml +100 -0
  94. data/web/locales/uk.yml +85 -61
  95. data/web/locales/ur.yml +64 -64
  96. data/web/locales/vi.yml +67 -67
  97. data/web/locales/zh-cn.yml +42 -16
  98. data/web/locales/zh-tw.yml +41 -8
  99. data/web/views/_footer.erb +17 -2
  100. data/web/views/_job_info.erb +18 -2
  101. data/web/views/_metrics_period_select.erb +12 -0
  102. data/web/views/_nav.erb +1 -1
  103. data/web/views/_paging.erb +2 -0
  104. data/web/views/_poll_link.erb +1 -1
  105. data/web/views/_summary.erb +7 -7
  106. data/web/views/busy.erb +49 -33
  107. data/web/views/dashboard.erb +28 -6
  108. data/web/views/filtering.erb +6 -0
  109. data/web/views/layout.erb +6 -6
  110. data/web/views/metrics.erb +90 -0
  111. data/web/views/metrics_for_job.erb +59 -0
  112. data/web/views/morgue.erb +5 -9
  113. data/web/views/queue.erb +15 -15
  114. data/web/views/queues.erb +9 -3
  115. data/web/views/retries.erb +5 -9
  116. data/web/views/scheduled.erb +12 -13
  117. metadata +61 -26
  118. data/lib/sidekiq/.DS_Store +0 -0
  119. data/lib/sidekiq/delay.rb +0 -43
  120. data/lib/sidekiq/extensions/action_mailer.rb +0 -48
  121. data/lib/sidekiq/extensions/active_record.rb +0 -43
  122. data/lib/sidekiq/extensions/class_methods.rb +0 -43
  123. data/lib/sidekiq/extensions/generic_proxy.rb +0 -33
  124. data/lib/sidekiq/worker.rb +0 -367
  125. /data/{LICENSE → LICENSE.txt} +0 -0
data/lib/sidekiq/delay.rb DELETED
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sidekiq # :nodoc:
4
- module Extensions
5
- def self.enable_delay!
6
- warn "Sidekiq's Delayed Extensions will be removed in Sidekiq 7.0", uplevel: 1
7
-
8
- if defined?(::ActiveSupport)
9
- require "sidekiq/extensions/active_record"
10
- require "sidekiq/extensions/action_mailer"
11
-
12
- # Need to patch Psych so it can autoload classes whose names are serialized
13
- # in the delayed YAML.
14
- Psych::Visitors::ToRuby.prepend(Sidekiq::Extensions::PsychAutoload)
15
-
16
- ActiveSupport.on_load(:active_record) do
17
- include Sidekiq::Extensions::ActiveRecord
18
- end
19
- ActiveSupport.on_load(:action_mailer) do
20
- extend Sidekiq::Extensions::ActionMailer
21
- end
22
- end
23
-
24
- require "sidekiq/extensions/class_methods"
25
- Module.__send__(:include, Sidekiq::Extensions::Klass)
26
- end
27
-
28
- module PsychAutoload
29
- def resolve_class(klass_name)
30
- return nil if !klass_name || klass_name.empty?
31
- # constantize
32
- names = klass_name.split("::")
33
- names.shift if names.empty? || names.first.empty?
34
-
35
- names.inject(Object) do |constant, name|
36
- constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
37
- end
38
- rescue NameError
39
- super
40
- end
41
- end
42
- end
43
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq/extensions/generic_proxy"
4
-
5
- module Sidekiq
6
- module Extensions
7
- ##
8
- # Adds +delay+, +delay_for+ and +delay_until+ methods to ActionMailer to offload arbitrary email
9
- # delivery to Sidekiq.
10
- #
11
- # @example
12
- # UserMailer.delay.send_welcome_email(new_user)
13
- # UserMailer.delay_for(5.days).send_welcome_email(new_user)
14
- # UserMailer.delay_until(5.days.from_now).send_welcome_email(new_user)
15
- class DelayedMailer
16
- include Sidekiq::Worker
17
-
18
- def perform(yml)
19
- (target, method_name, args) = YAML.load(yml)
20
- msg = target.public_send(method_name, *args)
21
- # The email method can return nil, which causes ActionMailer to return
22
- # an undeliverable empty message.
23
- if msg
24
- msg.deliver_now
25
- else
26
- raise "#{target.name}##{method_name} returned an undeliverable mail object"
27
- end
28
- end
29
- end
30
-
31
- module ActionMailer
32
- def sidekiq_delay(options = {})
33
- Proxy.new(DelayedMailer, self, options)
34
- end
35
-
36
- def sidekiq_delay_for(interval, options = {})
37
- Proxy.new(DelayedMailer, self, options.merge("at" => Time.now.to_f + interval.to_f))
38
- end
39
-
40
- def sidekiq_delay_until(timestamp, options = {})
41
- Proxy.new(DelayedMailer, self, options.merge("at" => timestamp.to_f))
42
- end
43
- alias_method :delay, :sidekiq_delay
44
- alias_method :delay_for, :sidekiq_delay_for
45
- alias_method :delay_until, :sidekiq_delay_until
46
- end
47
- end
48
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq/extensions/generic_proxy"
4
-
5
- module Sidekiq
6
- module Extensions
7
- ##
8
- # Adds +delay+, +delay_for+ and +delay_until+ methods to ActiveRecord to offload instance method
9
- # execution to Sidekiq.
10
- #
11
- # @example
12
- # User.recent_signups.each { |user| user.delay.mark_as_awesome }
13
- #
14
- # Please note, this is not recommended as this will serialize the entire
15
- # object to Redis. Your Sidekiq jobs should pass IDs, not entire instances.
16
- # This is here for backwards compatibility with Delayed::Job only.
17
- class DelayedModel
18
- include Sidekiq::Worker
19
-
20
- def perform(yml)
21
- (target, method_name, args) = YAML.load(yml)
22
- target.__send__(method_name, *args)
23
- end
24
- end
25
-
26
- module ActiveRecord
27
- def sidekiq_delay(options = {})
28
- Proxy.new(DelayedModel, self, options)
29
- end
30
-
31
- def sidekiq_delay_for(interval, options = {})
32
- Proxy.new(DelayedModel, self, options.merge("at" => Time.now.to_f + interval.to_f))
33
- end
34
-
35
- def sidekiq_delay_until(timestamp, options = {})
36
- Proxy.new(DelayedModel, self, options.merge("at" => timestamp.to_f))
37
- end
38
- alias_method :delay, :sidekiq_delay
39
- alias_method :delay_for, :sidekiq_delay_for
40
- alias_method :delay_until, :sidekiq_delay_until
41
- end
42
- end
43
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq/extensions/generic_proxy"
4
-
5
- module Sidekiq
6
- module Extensions
7
- ##
8
- # Adds `delay`, `delay_for` and `delay_until` methods to all Classes to offload class method
9
- # execution to Sidekiq.
10
- #
11
- # @example
12
- # User.delay.delete_inactive
13
- # Wikipedia.delay.download_changes_for(Date.today)
14
- #
15
- class DelayedClass
16
- include Sidekiq::Worker
17
-
18
- def perform(yml)
19
- (target, method_name, args) = YAML.load(yml)
20
- target.__send__(method_name, *args)
21
- end
22
- end
23
-
24
- module Klass
25
- def sidekiq_delay(options = {})
26
- Proxy.new(DelayedClass, self, options)
27
- end
28
-
29
- def sidekiq_delay_for(interval, options = {})
30
- Proxy.new(DelayedClass, self, options.merge("at" => Time.now.to_f + interval.to_f))
31
- end
32
-
33
- def sidekiq_delay_until(timestamp, options = {})
34
- Proxy.new(DelayedClass, self, options.merge("at" => timestamp.to_f))
35
- end
36
- alias_method :delay, :sidekiq_delay
37
- alias_method :delay_for, :sidekiq_delay_for
38
- alias_method :delay_until, :sidekiq_delay_until
39
- end
40
- end
41
- end
42
-
43
- Module.__send__(:include, Sidekiq::Extensions::Klass) unless defined?(::Rails)
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
-
5
- module Sidekiq
6
- module Extensions
7
- SIZE_LIMIT = 8_192
8
-
9
- class Proxy < BasicObject
10
- def initialize(performable, target, options = {})
11
- @performable = performable
12
- @target = target
13
- @opts = options.transform_keys(&:to_s)
14
- end
15
-
16
- def method_missing(name, *args)
17
- # Sidekiq has a limitation in that its message must be JSON.
18
- # JSON can't round trip real Ruby objects so we use YAML to
19
- # serialize the objects to a String. The YAML will be converted
20
- # to JSON and then deserialized on the other side back into a
21
- # Ruby object.
22
- obj = [@target, name, args]
23
- marshalled = ::YAML.dump(obj)
24
- if marshalled.size > SIZE_LIMIT
25
- ::Sidekiq.logger.warn { "#{@target}.#{name} job argument is #{marshalled.bytesize} bytes, you should refactor it to reduce the size" }
26
- end
27
- @performable.client_push({"class" => @performable,
28
- "args" => [marshalled],
29
- "display_class" => "#{@target}.#{name}"}.merge(@opts))
30
- end
31
- end
32
- end
33
- end
@@ -1,367 +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
- # sidekiq_options queue: 'critical', retry: 5
13
- #
14
- # def perform(*args)
15
- # # do some work
16
- # end
17
- # end
18
- #
19
- # Then in your Rails app, you can do this:
20
- #
21
- # HardWorker.perform_async(1, 2, 3)
22
- #
23
- # Note that perform_async is a class method, perform is an instance method.
24
- #
25
- # Sidekiq::Worker also includes several APIs to provide compatibility with
26
- # ActiveJob.
27
- #
28
- # class SomeWorker
29
- # include Sidekiq::Worker
30
- # queue_as :critical
31
- #
32
- # def perform(...)
33
- # end
34
- # end
35
- #
36
- # SomeWorker.set(wait_until: 1.hour).perform_async(123)
37
- #
38
- # Note that arguments passed to the job must still obey Sidekiq's
39
- # best practice for simple, JSON-native data types. Sidekiq will not
40
- # implement ActiveJob's more complex argument serialization. For
41
- # this reason, we don't implement `perform_later` as our call semantics
42
- # are very different.
43
- #
44
- module Worker
45
- ##
46
- # The Options module is extracted so we can include it in ActiveJob::Base
47
- # and allow native AJs to configure Sidekiq features/internals.
48
- module Options
49
- def self.included(base)
50
- 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
54
- end
55
-
56
- module ClassMethods
57
- ACCESSOR_MUTEX = Mutex.new
58
-
59
- ##
60
- # Allows customization for this type of Worker.
61
- # Legal options:
62
- #
63
- # queue - name of queue to use for this job type, default *default*
64
- # retry - enable retries for this Worker in case of error during execution,
65
- # *true* to use the default or *Integer* count
66
- # backtrace - whether to save any error backtrace in the retry payload to display in web UI,
67
- # can be true, false or an integer number of lines to save, default *false*
68
- #
69
- # In practice, any option is allowed. This is the main mechanism to configure the
70
- # options for a specific job.
71
- def sidekiq_options(opts = {})
72
- opts = opts.transform_keys(&:to_s) # stringify
73
- self.sidekiq_options_hash = get_sidekiq_options.merge(opts)
74
- end
75
-
76
- def sidekiq_retry_in(&block)
77
- self.sidekiq_retry_in_block = block
78
- end
79
-
80
- def sidekiq_retries_exhausted(&block)
81
- self.sidekiq_retries_exhausted_block = block
82
- end
83
-
84
- def get_sidekiq_options # :nodoc:
85
- self.sidekiq_options_hash ||= Sidekiq.default_job_options
86
- end
87
-
88
- def sidekiq_class_attribute(*attrs)
89
- instance_reader = true
90
- instance_writer = true
91
-
92
- attrs.each do |name|
93
- synchronized_getter = "__synchronized_#{name}"
94
-
95
- singleton_class.instance_eval do
96
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
97
- end
98
-
99
- define_singleton_method(synchronized_getter) { nil }
100
- singleton_class.class_eval do
101
- private(synchronized_getter)
102
- end
103
-
104
- define_singleton_method(name) { ACCESSOR_MUTEX.synchronize { send synchronized_getter } }
105
-
106
- ivar = "@#{name}"
107
-
108
- singleton_class.instance_eval do
109
- m = "#{name}="
110
- undef_method(m) if method_defined?(m) || private_method_defined?(m)
111
- end
112
- define_singleton_method("#{name}=") do |val|
113
- singleton_class.class_eval do
114
- ACCESSOR_MUTEX.synchronize do
115
- undef_method(synchronized_getter) if method_defined?(synchronized_getter) || private_method_defined?(synchronized_getter)
116
- define_method(synchronized_getter) { val }
117
- end
118
- end
119
-
120
- if singleton_class?
121
- class_eval do
122
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
123
- define_method(name) do
124
- if instance_variable_defined? ivar
125
- instance_variable_get ivar
126
- else
127
- singleton_class.send name
128
- end
129
- end
130
- end
131
- end
132
- val
133
- end
134
-
135
- if instance_reader
136
- undef_method(name) if method_defined?(name) || private_method_defined?(name)
137
- define_method(name) do
138
- if instance_variable_defined?(ivar)
139
- instance_variable_get ivar
140
- else
141
- self.class.public_send name
142
- end
143
- end
144
- end
145
-
146
- if instance_writer
147
- m = "#{name}="
148
- undef_method(m) if method_defined?(m) || private_method_defined?(m)
149
- attr_writer name
150
- end
151
- end
152
- end
153
- end
154
- end
155
-
156
- attr_accessor :jid
157
-
158
- def self.included(base)
159
- raise ArgumentError, "Sidekiq::Worker cannot be included in an ActiveJob: #{base.name}" if base.ancestors.any? { |c| c.name == "ActiveJob::Base" }
160
-
161
- base.include(Options)
162
- base.extend(ClassMethods)
163
- end
164
-
165
- def logger
166
- Sidekiq.logger
167
- end
168
-
169
- # This helper class encapsulates the set options for `set`, e.g.
170
- #
171
- # SomeWorker.set(queue: 'foo').perform_async(....)
172
- #
173
- class Setter
174
- include Sidekiq::JobUtil
175
-
176
- def initialize(klass, opts)
177
- @klass = klass
178
- # NB: the internal hash always has stringified keys
179
- @opts = opts.transform_keys(&:to_s)
180
-
181
- # ActiveJob compatibility
182
- interval = @opts.delete("wait_until") || @opts.delete("wait")
183
- at(interval) if interval
184
- end
185
-
186
- def set(options)
187
- hash = options.transform_keys(&:to_s)
188
- interval = hash.delete("wait_until") || @opts.delete("wait")
189
- @opts.merge!(hash)
190
- at(interval) if interval
191
- self
192
- end
193
-
194
- def perform_async(*args)
195
- if @opts["sync"] == true
196
- perform_inline(*args)
197
- else
198
- @klass.client_push(@opts.merge("args" => args, "class" => @klass))
199
- end
200
- end
201
-
202
- # Explicit inline execution of a job. Returns nil if the job did not
203
- # execute, true otherwise.
204
- def perform_inline(*args)
205
- raw = @opts.merge("args" => args, "class" => @klass)
206
-
207
- # validate and normalize payload
208
- item = normalize_item(raw)
209
- queue = item["queue"]
210
-
211
- # run client-side middleware
212
- result = Sidekiq.client_middleware.invoke(item["class"], item, queue, Sidekiq.redis_pool) do
213
- item
214
- end
215
- return nil unless result
216
-
217
- # round-trip the payload via JSON
218
- msg = Sidekiq.load_json(Sidekiq.dump_json(item))
219
-
220
- # prepare the job instance
221
- klass = msg["class"].constantize
222
- job = klass.new
223
- job.jid = msg["jid"]
224
- job.bid = msg["bid"] if job.respond_to?(:bid)
225
-
226
- # run the job through server-side middleware
227
- result = Sidekiq.server_middleware.invoke(job, msg, msg["queue"]) do
228
- # perform it
229
- job.perform(*msg["args"])
230
- true
231
- end
232
- return nil unless result
233
- # jobs do not return a result. they should store any
234
- # modified state.
235
- true
236
- end
237
- alias_method :perform_sync, :perform_inline
238
-
239
- def perform_bulk(args, batch_size: 1_000)
240
- client = @klass.build_client
241
- result = args.each_slice(batch_size).flat_map do |slice|
242
- client.push_bulk(@opts.merge("class" => @klass, "args" => slice))
243
- end
244
-
245
- result.is_a?(Enumerator::Lazy) ? result.force : result
246
- end
247
-
248
- # +interval+ must be a timestamp, numeric or something that acts
249
- # numeric (like an activesupport time interval).
250
- def perform_in(interval, *args)
251
- at(interval).perform_async(*args)
252
- end
253
- alias_method :perform_at, :perform_in
254
-
255
- private
256
-
257
- def at(interval)
258
- int = interval.to_f
259
- now = Time.now.to_f
260
- ts = (int < 1_000_000_000 ? now + int : int)
261
- # Optimization to enqueue something now that is scheduled to go out now or in the past
262
- @opts["at"] = ts if ts > now
263
- self
264
- end
265
- end
266
-
267
- module ClassMethods
268
- def delay(*args)
269
- raise ArgumentError, "Do not call .delay on a Sidekiq::Worker class, call .perform_async"
270
- end
271
-
272
- def delay_for(*args)
273
- raise ArgumentError, "Do not call .delay_for on a Sidekiq::Worker class, call .perform_in"
274
- end
275
-
276
- def delay_until(*args)
277
- raise ArgumentError, "Do not call .delay_until on a Sidekiq::Worker class, call .perform_at"
278
- end
279
-
280
- def queue_as(q)
281
- sidekiq_options("queue" => q.to_s)
282
- end
283
-
284
- def set(options)
285
- Setter.new(self, options)
286
- end
287
-
288
- def perform_async(*args)
289
- Setter.new(self, {}).perform_async(*args)
290
- end
291
-
292
- # Inline execution of job's perform method after passing through Sidekiq.client_middleware and Sidekiq.server_middleware
293
- def perform_inline(*args)
294
- Setter.new(self, {}).perform_inline(*args)
295
- end
296
- alias_method :perform_sync, :perform_inline
297
-
298
- ##
299
- # Push a large number of jobs to Redis, while limiting the batch of
300
- # each job payload to 1,000. This method helps cut down on the number
301
- # of round trips to Redis, which can increase the performance of enqueueing
302
- # large numbers of jobs.
303
- #
304
- # +items+ must be an Array of Arrays.
305
- #
306
- # For finer-grained control, use `Sidekiq::Client.push_bulk` directly.
307
- #
308
- # Example (3 Redis round trips):
309
- #
310
- # SomeWorker.perform_async(1)
311
- # SomeWorker.perform_async(2)
312
- # SomeWorker.perform_async(3)
313
- #
314
- # Would instead become (1 Redis round trip):
315
- #
316
- # SomeWorker.perform_bulk([[1], [2], [3]])
317
- #
318
- def perform_bulk(*args, **kwargs)
319
- Setter.new(self, {}).perform_bulk(*args, **kwargs)
320
- end
321
-
322
- # +interval+ must be a timestamp, numeric or something that acts
323
- # numeric (like an activesupport time interval).
324
- def perform_in(interval, *args)
325
- int = interval.to_f
326
- now = Time.now.to_f
327
- ts = (int < 1_000_000_000 ? now + int : int)
328
-
329
- item = {"class" => self, "args" => args}
330
-
331
- # Optimization to enqueue something now that is scheduled to go out now or in the past
332
- item["at"] = ts if ts > now
333
-
334
- client_push(item)
335
- end
336
- alias_method :perform_at, :perform_in
337
-
338
- ##
339
- # Allows customization for this type of Worker.
340
- # Legal options:
341
- #
342
- # queue - use a named queue for this Worker, default 'default'
343
- # retry - enable the RetryJobs middleware for this Worker, *true* to use the default
344
- # or *Integer* count
345
- # backtrace - whether to save any error backtrace in the retry payload to display in web UI,
346
- # can be true, false or an integer number of lines to save, default *false*
347
- # pool - use the given Redis connection pool to push this type of job to a given shard.
348
- #
349
- # In practice, any option is allowed. This is the main mechanism to configure the
350
- # options for a specific job.
351
- def sidekiq_options(opts = {})
352
- super
353
- end
354
-
355
- def client_push(item) # :nodoc:
356
- raise ArgumentError, "Job payloads should contain no Symbols: #{item}" if item.any? { |k, v| k.is_a?(::Symbol) }
357
- build_client.push(item)
358
- end
359
-
360
- def build_client # :nodoc:
361
- pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options["pool"] || Sidekiq.redis_pool
362
- client_class = get_sidekiq_options["client_class"] || Sidekiq::Client
363
- client_class.new(pool)
364
- end
365
- end
366
- end
367
- end
File without changes