Class: Fairway::Sidekiq::Fetch

Inherits:
Object
  • Object
show all
Defined in:
lib/fairway/sidekiq/fetch.rb

Defined Under Namespace

Classes: Fetches

Instance Method Summary collapse

Constructor Details

#initialize {|@fetches = Fetches.new| ... } ⇒ Fetch

Returns a new instance of Fetch.

Yields:



24
25
26
# File 'lib/fairway/sidekiq/fetch.rb', line 24

def initialize(&block)
  yield(@fetches = Fetches.new)
end

Instance Method Details

#fetch_orderObject



36
37
38
# File 'lib/fairway/sidekiq/fetch.rb', line 36

def fetch_order
  fetches.shuffle.uniq
end

#fetchesObject



32
33
34
# File 'lib/fairway/sidekiq/fetch.rb', line 32

def fetches
  @fetches.list
end

#new(options) ⇒ Object



28
29
30
# File 'lib/fairway/sidekiq/fetch.rb', line 28

def new(options)
  self
end

#retrieve_work(options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fairway/sidekiq/fetch.rb', line 40

def retrieve_work(options = {})
  options = { blocking: true }.merge(options)

  ::Sidekiq.logger.debug "#{self.class.name}#retrieve_work"

  fetch_order.each do |fetch|
    work = fetch.retrieve_work(blocking: false)

    if work
      ::Sidekiq.logger.debug "#{self.class.name}#retrieve_work got work"
      return work
    end
  end

  ::Sidekiq.logger.debug "#{self.class.name}#retrieve_work got nil"
  sleep 1 if options[:blocking]

  return nil
end