Class: Shoryuken::Middleware::Server::Timing

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

Overview

Middleware that logs timing information for message processing. Records start time, completion time, and warns if processing exceeds the queue’s visibility timeout.

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 while logging timing information

Parameters:

  • _worker (Object)

    the worker instance (unused)

  • queue (String)

    the queue name

  • _sqs_msg (Shoryuken::Message)

    the message being processed (unused)

  • _body (Object)

    the parsed message body (unused)

Yields:

  • continues to the next middleware in the chain



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shoryuken/middleware/server/timing.rb', line 20

def call(_worker, queue, _sqs_msg, _body)
  started_at = Time.now

  logger.info { "started at #{started_at}" }

  yield

  total_time = elapsed(started_at)

  if (total_time / 1000.0) > (timeout = Shoryuken::Client.queues(queue).visibility_timeout)
    logger.warn { "exceeded the queue visibility timeout by #{total_time - (timeout * 1000)} ms" }
  end

  logger.info { "completed in: #{total_time} ms" }
rescue
  logger.info { "failed in: #{elapsed(started_at)} ms" }
  raise
end