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:
Diffstat (limited to 'app/models/analytics/cycle_analytics/runtime_limiter.rb')
-rw-r--r--app/models/analytics/cycle_analytics/runtime_limiter.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/models/analytics/cycle_analytics/runtime_limiter.rb b/app/models/analytics/cycle_analytics/runtime_limiter.rb
new file mode 100644
index 00000000000..063377c3ddb
--- /dev/null
+++ b/app/models/analytics/cycle_analytics/runtime_limiter.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Analytics
+ module CycleAnalytics
+ 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