Method: Pheme::QueuePoller#initialize
- Defined in:
- lib/pheme/queue_poller.rb
#initialize(queue_url:, connection_pool_block: false, max_messages: nil, format: :json, poller_configuration: {}, sqs_client: nil, idle_timeout: nil, message_handler: nil, &block_message_handler) ⇒ QueuePoller
Returns a new instance of QueuePoller.
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 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pheme/queue_poller.rb', line 10 def initialize(queue_url:, connection_pool_block: false, max_messages: nil, format: :json, poller_configuration: {}, sqs_client: nil, idle_timeout: nil, message_handler: nil, &) raise ArgumentError, "must specify non-nil queue_url" if queue_url.blank? @queue_url = queue_url @queue_poller = Aws::SQS::QueuePoller.new(queue_url, client: sqs_client) @connection_pool_block = connection_pool_block @messages_processed = 0 @messages_received = 0 @format = format @max_messages = @poller_configuration = { wait_time_seconds: 10, # amount of time a long polling receive call can wait for a message before receiving a empty response (which will trigger another polling request) idle_timeout: 20, # disconnects poller after 20 seconds of idle time skip_delete: true, # manually delete messages }.merge(poller_configuration || {}) @poller_configuration[:idle_timeout] = idle_timeout unless idle_timeout.nil? if if .ancestors.include?(Pheme::MessageHandler) @message_handler = else raise ArgumentError, 'Invalid message handler, must inherit from Pheme::MessageHandler' end end @block_message_handler = raise ArgumentError, 'only provide a message_handler or a block, not both' if @message_handler && @block_message_handler if queue_poller.before_request do |stats| throw :stop_polling if stats. >= end end end |