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

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

Instance Method Summary collapse

Methods included from Util

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

Instance Method Details

#call(worker, queue, sqs_msg, body) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shoryuken/middleware/server/timing.rb', line 7

def call(worker, queue, sqs_msg, body)
  Shoryuken::Logging.with_context("#{worker_name(worker.class, sqs_msg, body)}/#{queue}/#{sqs_msg.message_id}") do
    begin
      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 => e
      logger.info { "failed in: #{elapsed(started_at)} ms" }
      raise e
    end
  end
end