Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-10-25 11:49:59 +0300
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-10-25 12:10:46 +0300
commitcb5f4d0cad520629aecaa838ddf1e84d7265ff49 (patch)
tree833fef694eb1942fd7818303310e5647d7211e17 /lib/gitlab/checks
parent084a8b6101c25e5d3d4f97f078abd9a649a2fb64 (diff)
Refactors TimedLogger to be more OOP compliant
Adds a #full_message method so that external classes do not have access to the state of the logger. Adds a #append_message to always append to the array in-place
Diffstat (limited to 'lib/gitlab/checks')
-rw-r--r--lib/gitlab/checks/change_access.rb2
-rw-r--r--lib/gitlab/checks/timed_logger.rb22
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/gitlab/checks/change_access.rb b/lib/gitlab/checks/change_access.rb
index 52a72de3b15..7036ae9191d 100644
--- a/lib/gitlab/checks/change_access.rb
+++ b/lib/gitlab/checks/change_access.rb
@@ -47,7 +47,7 @@ module Gitlab
@protocol = protocol
@logger = logger
- @logger.log << "Running checks for ref: #{@branch_name || @tag_name}"
+ @logger.append_message("Running checks for ref: #{@branch_name || @tag_name}")
end
def exec(skip_commits_check: false)
diff --git a/lib/gitlab/checks/timed_logger.rb b/lib/gitlab/checks/timed_logger.rb
index cbb079a5383..11c08429d3d 100644
--- a/lib/gitlab/checks/timed_logger.rb
+++ b/lib/gitlab/checks/timed_logger.rb
@@ -5,15 +5,18 @@ module Gitlab
class TimedLogger
TimeoutError = Class.new(StandardError)
- attr_reader :start_time
- attr_accessor :log, :timeout
+ attr_reader :start_time, :header, :log, :timeout
- def initialize(start_time: Time.now, log: [], timeout:)
+ def initialize(start_time: Time.now, log: [], timeout:, header: "")
@start_time = start_time
@timeout = timeout
+ @header = header
@log = log
end
+ # Adds trace of method being tracked with
+ # the correspondent time it took to run it
+ #
def log_timed(log_message, start = Time.now)
check_timeout_reached
@@ -21,12 +24,12 @@ module Gitlab
yield
- log << log_message + time_suffix_message(start: start)
+ append_message(log_message + time_suffix_message(start: start))
rescue GRPC::DeadlineExceeded, TimeoutError
args = { cancelled: true }
args[:start] = start if timed
- log << log_message + time_suffix_message(args)
+ append_message(log_message + time_suffix_message(args))
raise TimeoutError
end
@@ -41,6 +44,15 @@ module Gitlab
(start_time + timeout.seconds) - Time.now
end
+ def full_message
+ header + log.join("\n")
+ end
+
+ # We always want to append in-place on the log
+ def append_message(message)
+ log << message
+ end
+
private
def time_expired?