Class: Ledmon::Interceptors::SleepInterceptor
- Inherits:
-
GRPC::ClientInterceptor
- Object
- GRPC::ClientInterceptor
- Ledmon::Interceptors::SleepInterceptor
- Defined in:
- lib/ledmon/interceptors/sleep_interceptor.rb
Instance Method Summary collapse
-
#initialize ⇒ SleepInterceptor
constructor
A new instance of SleepInterceptor.
- #request_response(request: nil, call: nil, method: nil, metadata: nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ SleepInterceptor
Returns a new instance of SleepInterceptor.
3 4 5 |
# File 'lib/ledmon/interceptors/sleep_interceptor.rb', line 3 def initialize @sleep_until = nil end |
Instance Method Details
#request_response(request: nil, call: nil, method: nil, metadata: nil, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ledmon/interceptors/sleep_interceptor.rb', line 7 def request_response(request: nil, call: nil, method: nil, metadata: nil, &block) if @sleep_until remaining_sleep_time = @sleep_until - Time.now.to_f if remaining_sleep_time > 0 micro_sleep remaining_sleep_time end @sleep_until = nil end response = block.call(request:, call:, method:, metadata:) if response.respond_to?(:sleep_time) @sleep_until = Time.now.to_f + response.sleep_time end response end |