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



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gruf/interceptors/timer.rb', line 70

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