Class: Sidekiq::Throttled::BasicFetch

Inherits:
BasicFetch
  • Object
show all
Defined in:
lib/sidekiq/throttled/basic_fetch.rb

Overview

Throttled version of ‘Sidekiq::BasicFetch` fetcher strategy.

Defined Under Namespace

Classes: UnitOfWork

Constant Summary collapse

TIMEOUT =
2

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BasicFetch

Returns a new instance of BasicFetch.



17
18
19
20
21
# File 'lib/sidekiq/throttled/basic_fetch.rb', line 17

def initialize(options)
  @strictly_ordered_queues = (options[:strict] ? true : false)
  @queues = options[:queues].map { |q| "queue:#{q}" }
  @queues.uniq! if @strictly_ordered_queues
end

Instance Method Details

#retrieve_workSidekiq::BasicFetch::UnitOfWork?

Returns:

  • (Sidekiq::BasicFetch::UnitOfWork, nil)


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sidekiq/throttled/basic_fetch.rb', line 24

def retrieve_work
  work = brpop
  return unless work

  work = UnitOfWork.new(*work)
  return work unless Throttled.throttled? work.job

  queue = "queue:#{work.queue_name}"

  Sidekiq.redis { |conn| conn.lpush(queue, work.job) }

  nil
end