Class: Gitlab::Checks::TimedLogger
- Inherits:
-
Object
- Object
- Gitlab::Checks::TimedLogger
- Defined in:
- lib/gitlab/checks/timed_logger.rb
Constant Summary collapse
- TimeoutError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#append_message(message) ⇒ Object
We always want to append in-place on the log.
- #check_timeout_reached ⇒ Object
- #full_message ⇒ Object
-
#initialize(timeout:, start_time: Time.now, log: [], header: "") ⇒ TimedLogger
constructor
A new instance of TimedLogger.
-
#log_timed(log_message, start = Time.now) ⇒ Object
Adds trace of method being tracked with the correspondent time it took to run it.
- #time_left ⇒ Object
Constructor Details
#initialize(timeout:, start_time: Time.now, log: [], header: "") ⇒ TimedLogger
Returns a new instance of TimedLogger.
10 11 12 13 14 15 |
# File 'lib/gitlab/checks/timed_logger.rb', line 10 def initialize(timeout:, start_time: Time.now, log: [], header: "") @start_time = start_time @timeout = timeout @header = header @log = log end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
8 9 10 |
# File 'lib/gitlab/checks/timed_logger.rb', line 8 def header @header end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
8 9 10 |
# File 'lib/gitlab/checks/timed_logger.rb', line 8 def log @log end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/gitlab/checks/timed_logger.rb', line 8 def start_time @start_time end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/gitlab/checks/timed_logger.rb', line 8 def timeout @timeout end |
Instance Method Details
#append_message(message) ⇒ Object
We always want to append in-place on the log
54 55 56 |
# File 'lib/gitlab/checks/timed_logger.rb', line 54 def () log << end |
#check_timeout_reached ⇒ Object
39 40 41 42 43 |
# File 'lib/gitlab/checks/timed_logger.rb', line 39 def check_timeout_reached return unless time_expired? raise TimeoutError end |
#full_message ⇒ Object
49 50 51 |
# File 'lib/gitlab/checks/timed_logger.rb', line 49 def header + log.join("\n") end |
#log_timed(log_message, start = Time.now) ⇒ Object
Adds trace of method being tracked with the correspondent time it took to run it. We make use of the start default argument on unit tests related to this method
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/checks/timed_logger.rb', line 22 def log_timed(, start = Time.now) check_timeout_reached timed = true yield ( + (start: start)) rescue GRPC::DeadlineExceeded, TimeoutError args = { cancelled: true } args[:start] = start if timed ( + (**args)) raise TimeoutError end |
#time_left ⇒ Object
45 46 47 |
# File 'lib/gitlab/checks/timed_logger.rb', line 45 def time_left (start_time + timeout.seconds) - Time.now end |