Class: Fairway::Sidekiq::BasicFetch
- Inherits:
-
Sidekiq::BasicFetch
- Object
- Sidekiq::BasicFetch
- Fairway::Sidekiq::BasicFetch
- Defined in:
- lib/fairway/sidekiq/basic_fetch.rb
Instance Attribute Summary collapse
-
#queues ⇒ Object
readonly
Returns the value of attribute queues.
Instance Method Summary collapse
-
#initialize(options) ⇒ BasicFetch
constructor
A new instance of BasicFetch.
- #queues_cmd ⇒ Object
- #retrieve_work(options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ BasicFetch
Returns a new instance of BasicFetch.
6 7 8 |
# File 'lib/fairway/sidekiq/basic_fetch.rb', line 6 def initialize() @queues = [:queues].map { |q| "queue:#{q}" } end |
Instance Attribute Details
#queues ⇒ Object (readonly)
Returns the value of attribute queues.
4 5 6 |
# File 'lib/fairway/sidekiq/basic_fetch.rb', line 4 def queues @queues end |
Instance Method Details
#queues_cmd ⇒ Object
42 43 44 |
# File 'lib/fairway/sidekiq/basic_fetch.rb', line 42 def queues_cmd @queues.shuffle.uniq end |
#retrieve_work(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fairway/sidekiq/basic_fetch.rb', line 10 def retrieve_work( = {}) = { blocking: true }.merge() ::Sidekiq.logger.debug "#{self.class.name}#retrieve_work #{queues_cmd}" work = ::Sidekiq.redis do |conn| script = <<-SCRIPT for i = 1, #KEYS do local work = redis.call('rpop', KEYS[i]); if work then return {KEYS[i], work}; end end return nil; SCRIPT conn.eval(script, queues_cmd) end if (work) ::Sidekiq.logger.debug "#{self.class.name}#retrieve_work got work" work = UnitOfWork.new(*work) else ::Sidekiq.logger.debug "#{self.class.name}#retrieve_work got nil" sleep 1 if [:blocking] end work end |