Class: Shoryuken::Middleware::Server::AutoExtendVisibility

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/shoryuken/middleware/server/auto_extend_visibility.rb

Overview

Middleware that automatically extends message visibility timeout during processing. Prevents messages from becoming visible to other consumers while still being processed.

Defined Under Namespace

Classes: MessageVisibilityExtender

Constant Summary collapse

EXTEND_UPFRONT_SECONDS =

Number of seconds before timeout to extend visibility

5

Instance Method Summary collapse

Methods included from Util

#elapsed, #fire_event, #logger, #unparse_queues, #worker_name

Instance Method Details

#call(worker, queue, sqs_msg, body) { ... } ⇒ void

This method returns an undefined value.

Processes a message with automatic visibility timeout extension

Parameters:

  • worker (Object)

    the worker instance

  • queue (String)

    the queue name

  • sqs_msg (Shoryuken::Message, Array<Shoryuken::Message>)

    the message or batch

  • body (Object)

    the parsed message body

Yields:

  • continues to the next middleware in the chain



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shoryuken/middleware/server/auto_extend_visibility.rb', line 22

def call(worker, queue, sqs_msg, body)
  return yield unless worker.class.auto_visibility_timeout?

  if sqs_msg.is_a?(Array)
    logger.warn { "Auto extend visibility isn't supported for batch workers" }
    return yield
  end

  timer = auto_visibility_timer(worker, queue, sqs_msg, body)
  yield
ensure
  timer.kill if timer
end