Files
gitlab-foss/lib/gitlab/metrics/runtime_limiter.rb
2024-01-30 12:11:19 +00:00

31 lines
603 B
Ruby

# frozen_string_literal: true
module Gitlab
module Metrics
class RuntimeLimiter
delegate :monotonic_time, to: :'Gitlab::Metrics::System'
DEFAULT_MAX_RUNTIME = 200.seconds
attr_reader :max_runtime, :start_time
def initialize(max_runtime = DEFAULT_MAX_RUNTIME)
@start_time = monotonic_time
@max_runtime = max_runtime
end
def elapsed_time
monotonic_time - start_time
end
def over_time?
@last_check = elapsed_time >= max_runtime
end
def was_over_time?
!!@last_check
end
end
end
end