Module: Sidekiq::Worker::ClassMethods
- Defined in:
- lib/sidekiq/worker.rb
Instance Method Summary collapse
-
#build_client ⇒ Object
:nodoc:.
-
#client_push(item) ⇒ Object
:nodoc:.
- #delay(*args) ⇒ Object
- #delay_for(*args) ⇒ Object
- #delay_until(*args) ⇒ Object
- #perform_async(*args) ⇒ Object
-
#perform_bulk(*args, **kwargs) ⇒ Object
Push a large number of jobs to Redis, while limiting the batch of each job payload to 1,000.
-
#perform_in(interval, *args) ⇒ Object
(also: #perform_at)
intervalmust be a timestamp, numeric or something that acts numeric (like an activesupport time interval). -
#perform_inline(*args) ⇒ Object
(also: #perform_sync)
Inline execution of job's perform method after passing through Sidekiq.client_middleware and Sidekiq.server_middleware.
- #queue_as(q) ⇒ Object
- #set(options) ⇒ Object
-
#sidekiq_options(opts = {}) ⇒ Object
Allows customization for this type of Worker.
Instance Method Details
#build_client ⇒ Object
:nodoc:
360 361 362 363 364 |
# File 'lib/sidekiq/worker.rb', line 360 def build_client # :nodoc: pool = Thread.current[:sidekiq_via_pool] || ["pool"] || Sidekiq.redis_pool client_class = ["client_class"] || Sidekiq::Client client_class.new(pool) end |
#client_push(item) ⇒ Object
:nodoc:
355 356 357 358 |
# File 'lib/sidekiq/worker.rb', line 355 def client_push(item) # :nodoc: raise ArgumentError, "Job payloads should contain no Symbols: #{item}" if item.any? { |k, v| k.is_a?(::Symbol) } build_client.push(item) end |
#delay(*args) ⇒ Object
268 269 270 |
# File 'lib/sidekiq/worker.rb', line 268 def delay(*args) raise ArgumentError, "Do not call .delay on a Sidekiq::Worker class, call .perform_async" end |
#delay_for(*args) ⇒ Object
272 273 274 |
# File 'lib/sidekiq/worker.rb', line 272 def delay_for(*args) raise ArgumentError, "Do not call .delay_for on a Sidekiq::Worker class, call .perform_in" end |
#delay_until(*args) ⇒ Object
276 277 278 |
# File 'lib/sidekiq/worker.rb', line 276 def delay_until(*args) raise ArgumentError, "Do not call .delay_until on a Sidekiq::Worker class, call .perform_at" end |
#perform_async(*args) ⇒ Object
288 289 290 |
# File 'lib/sidekiq/worker.rb', line 288 def perform_async(*args) Setter.new(self, {}).perform_async(*args) end |
#perform_bulk(*args, **kwargs) ⇒ Object
Push a large number of jobs to Redis, while limiting the batch of each job payload to 1,000. This method helps cut down on the number of round trips to Redis, which can increase the performance of enqueueing large numbers of jobs.
items must be an Array of Arrays.
For finer-grained control, use `Sidekiq::Client.push_bulk` directly.
Example (3 Redis round trips):
SomeWorker.perform_async(1)
SomeWorker.perform_async(2)
SomeWorker.perform_async(3)
Would instead become (1 Redis round trip):
SomeWorker.perform_bulk([[1], [2], [3]])
318 319 320 |
# File 'lib/sidekiq/worker.rb', line 318 def perform_bulk(*args, **kwargs) Setter.new(self, {}).perform_bulk(*args, **kwargs) end |
#perform_in(interval, *args) ⇒ Object Also known as: perform_at
interval must be a timestamp, numeric or something that acts
numeric (like an activesupport time interval).
324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/sidekiq/worker.rb', line 324 def perform_in(interval, *args) int = interval.to_f now = Time.now.to_f ts = (int < 1_000_000_000 ? now + int : int) item = {"class" => self, "args" => args} # Optimization to enqueue something now that is scheduled to go out now or in the past item["at"] = ts if ts > now client_push(item) end |
#perform_inline(*args) ⇒ Object Also known as: perform_sync
Inline execution of job's perform method after passing through Sidekiq.client_middleware and Sidekiq.server_middleware
293 294 295 |
# File 'lib/sidekiq/worker.rb', line 293 def perform_inline(*args) Setter.new(self, {}).perform_inline(*args) end |
#queue_as(q) ⇒ Object
280 281 282 |
# File 'lib/sidekiq/worker.rb', line 280 def queue_as(q) ("queue" => q.to_s) end |
#set(options) ⇒ Object
284 285 286 |
# File 'lib/sidekiq/worker.rb', line 284 def set() Setter.new(self, ) end |
#sidekiq_options(opts = {}) ⇒ Object
Allows customization for this type of Worker. Legal options:
queue - use a named queue for this Worker, default 'default'
retry - enable the RetryJobs middleware for this Worker, *true* to use the default
or *Integer* count
backtrace - whether to save any error backtrace in the retry payload to display in web UI,
can be true, false or an integer number of lines to save, default *false*
pool - use the given Redis connection pool to push this type of job to a given shard.
In practice, any option is allowed. This is the main mechanism to configure the options for a specific job.
351 352 353 |
# File 'lib/sidekiq/worker.rb', line 351 def (opts = {}) super end |