Module: Sidekiq::Sqs::Fetcher

Extended by:
ActiveSupport::Concern
Defined in:
lib/sidekiq-sqs/fetcher.rb

Constant Summary collapse

QueueNotDoneError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#fetchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sidekiq-sqs/fetcher.rb', line 21

def fetch
  watchdog('Fetcher#fetch died') do
    return if Sidekiq::Fetcher.done?

    begin
      queue = nil
      msg = nil

      ## FIXME
      queues = queues_cmd
      queues.pop # Last entry is TIMEOUT

      msg = queues.inject(nil) do |message, queue|
        message || fetch_single_message(queue)
      end

      if msg
        @mgr.assign!(msg, File.basename(msg.queue.url))
      else
        after(5) { fetch }
      end
    rescue QueueNotDoneError
      # Just wait
      after(5) { fetch }
    rescue => ex
      logger.error("Error fetching message from queues (#{@queues.join(', ')}): #{ex}")
      logger.error(ex.backtrace.first)
      sleep(self.class::TIMEOUT)
      after(0) { fetch }
    end
  end
end

#fetch_single_message(queue) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sidekiq-sqs/fetcher.rb', line 54

def fetch_single_message(queue)
  queue = Sidekiq.sqs.queues.named(queue)
  message = queue.receive_message

  if @strictly_ordered_queues && message.nil?
    # If messages being processed, raise
    if queue.invisible_messages != 0
      raise QueueNotDoneError
    end
  else
    message
  end
end

#initialize_with_sqs(mgr, queues, strict) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sidekiq-sqs/fetcher.rb', line 13

def initialize_with_sqs(mgr, queues, strict)
  initialize_without_sqs(mgr, queues, strict)
  
  # Fix Queue names
  @queues = @queues.map {|queue| Sidekiq::Client.environmental_queue_name queue.gsub(/^queue:/, '') }
  @unique_queues = @queues.uniq
end