Class: Gruf::Interceptors::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/interceptors/timer.rb

Overview

Utility class that can be used by interceptors to time requests

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.timeGruf::Interceptors::Timer::Result

Time a given code block and return a Timer::Result object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gruf/interceptors/timer.rb', line 79

def self.time
  start_time = Time.now
  message = yield
  end_time = Time.now
  elapsed = (end_time - start_time) * 1000.0
  Result.new(message, elapsed, true)
rescue GRPC::BadStatus => e
  end_time = Time.now
  elapsed = (end_time - start_time) * 1000.0
  Result.new(e, elapsed, false)
end