Class: Shoryuken::Fetcher
- Inherits:
-
Object
- Object
- Shoryuken::Fetcher
- Includes:
- Celluloid, Util
- Defined in:
- lib/shoryuken/fetcher.rb
Constant Summary collapse
- FETCH_LIMIT =
10
Instance Method Summary collapse
- #fetch(queue, available_processors) ⇒ Object
-
#initialize(manager) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #receive_messages(queue, limit) ⇒ Object
Methods included from Util
#elapsed, #fire_event, #logger, #unparse_queues, #watchdog, #worker_name
Constructor Details
#initialize(manager) ⇒ Fetcher
Returns a new instance of Fetcher.
8 9 10 |
# File 'lib/shoryuken/fetcher.rb', line 8 def initialize(manager) @manager = manager end |
Instance Method Details
#fetch(queue, available_processors) ⇒ Object
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 53 54 55 56 57 58 59 |
# File 'lib/shoryuken/fetcher.rb', line 24 def fetch(queue, available_processors) watchdog('Fetcher#fetch died') do started_at = Time.now logger.debug { "Looking for new messages in '#{queue}'" } begin batch = Shoryuken.worker_registry.(queue) limit = batch ? FETCH_LIMIT : available_processors if (sqs_msgs = Array((queue, limit))).any? logger.debug { "Found #{sqs_msgs.size} messages for '#{queue}'" } if batch @manager.async.assign(queue, patch_sqs_msgs!(sqs_msgs)) else sqs_msgs.each { |sqs_msg| @manager.async.assign(queue, sqs_msg) } end @manager.async.rebalance_queue_weight!(queue) else logger.debug { "No message found for '#{queue}'" } @manager.async.pause_queue!(queue) end logger.debug { "Fetcher for '#{queue}' completed in #{elapsed(started_at)} ms" } rescue => ex logger.error { "Error fetching message: #{ex}" } logger.error { ex.backtrace.first } end @manager.async.dispatch end end |
#receive_messages(queue, limit) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/shoryuken/fetcher.rb', line 12 def (queue, limit) # AWS limits the batch size by 10 limit = limit > FETCH_LIMIT ? FETCH_LIMIT : limit = (Shoryuken::AwsConfig.[:receive_message] || {}).dup [:max_number_of_messages] = limit [:message_attribute_names] = %w(All) [:attribute_names] = %w(All) Shoryuken::Client.queues(queue). end |